asan_test_utils.h revision 7da8503a90c7f84787aa1ba978e2223893fa7727
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#ifndef __WORDSIZE
42#if __LP64__ || defined(_WIN64)
43#define __WORDSIZE 64
44#else
45#define __WORDSIZE 32
46#endif
47#endif
48
49// Make the compiler think that something is going on there.
50extern "C" void break_optimization(void *arg);
51
52// This function returns its parameter but in such a way that compiler
53// can not prove it.
54template<class T>
55NOINLINE
56static T Ident(T t) {
57  T ret = t;
58  break_optimization(&ret);
59  return ret;
60}
61
62#endif  // ASAN_TEST_UTILS_H
63