asan_test_utils.h revision 1cffef3e39cad4eb33606afbebac78d6637361ac
1//===-- asan_test_utils.h ---------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file is a part of AddressSanitizer, an address sanity checker. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef ASAN_TEST_UTILS_H 15#define ASAN_TEST_UTILS_H 16 17#if !defined(ASAN_EXTERNAL_TEST_CONFIG) 18# define INCLUDED_FROM_ASAN_TEST_UTILS_H 19# include "asan_test_config.h" 20# undef INCLUDED_FROM_ASAN_TEST_UTILS_H 21#endif 22 23#if defined(_WIN32) 24typedef unsigned __int8 uint8_t; 25typedef unsigned __int16 uint16_t; 26typedef unsigned __int32 uint32_t; 27typedef unsigned __int64 uint64_t; 28typedef __int8 int8_t; 29typedef __int16 int16_t; 30typedef __int32 int32_t; 31typedef __int64 int64_t; 32# define NOINLINE __declspec(noinline) 33#else // defined(_WIN32) 34# define NOINLINE __attribute__((noinline)) 35#endif // defined(_WIN32) 36 37#if !defined(__has_feature) 38#define __has_feature(x) 0 39#endif 40 41#if __has_feature(address_sanitizer) 42# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \ 43 __attribute__((no_address_safety_analysis)) 44#else 45# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS 46#endif 47 48#ifndef __WORDSIZE 49#if __LP64__ || defined(_WIN64) 50#define __WORDSIZE 64 51#else 52#define __WORDSIZE 32 53#endif 54#endif 55 56// Make the compiler think that something is going on there. 57extern "C" void break_optimization(void *arg); 58 59// This function returns its parameter but in such a way that compiler 60// can not prove it. 61template<class T> 62NOINLINE 63static T Ident(T t) { 64 T ret = t; 65 break_optimization(&ret); 66 return ret; 67} 68 69#endif // ASAN_TEST_UTILS_H 70