asan_test_utils.h revision fa7e95da75c30b7111224e68cb4405357bdc0f4b
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# define USED
34#else  // defined(_WIN32)
35# define NOINLINE __attribute__((noinline))
36# define USED __attribute__((used))
37#endif  // defined(_WIN32)
38
39#if !defined(__has_feature)
40#define __has_feature(x) 0
41#endif
42
43#if __has_feature(address_sanitizer)
44# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \
45    __attribute__((no_address_safety_analysis))
46#else
47# define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
48#endif
49
50#ifndef __WORDSIZE
51#if __LP64__ || defined(_WIN64)
52#define __WORDSIZE 64
53#else
54#define __WORDSIZE 32
55#endif
56#endif
57
58// Make the compiler think that something is going on there.
59extern "C" void break_optimization(void *arg);
60
61// This function returns its parameter but in such a way that compiler
62// can not prove it.
63template<class T>
64NOINLINE
65static T Ident(T t) {
66  T ret = t;
67  break_optimization(&ret);
68  return ret;
69}
70
71#endif  // ASAN_TEST_UTILS_H
72