3e1b4108b4e2a3c9e27df66843593c7fdea0aff4
[mono.git] / mono / utils / mono-compiler.h
1 /**
2  * \file
3  */
4
5 #ifndef __UTILS_MONO_COMPILER_H__
6 #define __UTILS_MONO_COMPILER_H__
7
8 /*
9  * This file includes macros used in the runtime to encapsulate different
10  * compiler behaviours.
11  */
12 #include <config.h>
13
14 #ifdef __GNUC__
15 #define MONO_ATTR_USED __attribute__ ((__used__))
16 #else
17 #define MONO_ATTR_USED
18 #endif
19
20 #ifdef __GNUC__
21 #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos) __attribute__ ((__format__(__printf__,fmt_pos,arg_pos)))
22 #else
23 #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos)
24 #endif
25
26 /* Deal with Microsoft C compiler differences */
27 #ifdef _MSC_VER
28
29 #include <math.h>
30
31 #if _MSC_VER < 1800 /* VS 2013 */
32 #define strtoull _strtoui64
33 #endif
34
35 #include <float.h>
36 #define trunc(x)        (((x) < 0) ? ceil((x)) : floor((x)))
37 #if _MSC_VER < 1800 /* VS 2013 */
38 #define isnan(x)        _isnan(x)
39 #define isinf(x)        (_isnan(x) ? 0 : (_fpclass(x) == _FPCLASS_NINF) ? -1 : (_fpclass(x) == _FPCLASS_PINF) ? 1 : 0)
40 #define isnormal(x)     _finite(x)
41 #endif
42
43 #define popen           _popen
44 #define pclose          _pclose
45
46 #include <direct.h>
47 #define mkdir(x)        _mkdir(x)
48
49 #define __func__ __FUNCTION__
50
51 #include <BaseTsd.h>
52 typedef SSIZE_T ssize_t;
53
54 /*
55  * SSIZE_MAX is not defined in MSVC, so define it here.
56  *
57  * These values come from MinGW64, and are public domain.
58  *
59  */
60 #ifndef SSIZE_MAX
61 #ifdef _WIN64
62 #define SSIZE_MAX _I64_MAX
63 #else
64 #define SSIZE_MAX INT_MAX
65 #endif
66 #endif
67
68 #endif /* _MSC_VER */
69
70 #ifdef _MSC_VER
71 // Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty.
72 #define MONO_EMPTY_SOURCE_FILE(x) void __mono_win32_ ## x ## _quiet_lnk4221 (void) {}
73 #else
74 #define MONO_EMPTY_SOURCE_FILE(x)
75 #endif
76
77 #if !defined(_MSC_VER) && !defined(HOST_SOLARIS) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MONOTOUCH) && HAVE_VISIBILITY_HIDDEN
78 #if MONO_LLVM_LOADED
79 #define MONO_LLVM_INTERNAL MONO_API
80 #else
81 #define MONO_LLVM_INTERNAL
82 #endif
83 #else
84 #define MONO_LLVM_INTERNAL 
85 #endif
86
87 /* Used to mark internal functions used by the profiler modules */
88 #define MONO_PROFILER_API MONO_API
89
90 #ifdef __GNUC__
91 #define MONO_ALWAYS_INLINE __attribute__ ((__always_inline__))
92 #elif defined(_MSC_VER)
93 #define MONO_ALWAYS_INLINE __forceinline
94 #else
95 #define MONO_ALWAYS_INLINE
96 #endif
97
98 #ifdef __GNUC__
99 #define MONO_NEVER_INLINE __attribute__ ((__noinline__))
100 #elif defined(_MSC_VER)
101 #define MONO_NEVER_INLINE __declspec(noinline)
102 #else
103 #define MONO_NEVER_INLINE
104 #endif
105
106 #ifdef __GNUC__
107 #define MONO_COLD __attribute__ ((__cold__))
108 #else
109 #define MONO_COLD
110 #endif
111
112 #if defined (__GNUC__) && defined (__GNUC_MINOR__) && defined (__GNUC_PATCHLEVEL__)
113 #define MONO_GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
114 #endif
115
116 #if defined(__has_feature)
117 #if __has_feature(thread_sanitizer)
118 #define MONO_HAS_CLANG_THREAD_SANITIZER 1
119 #else
120 #define MONO_HAS_CLANG_THREAD_SANITIZER 0
121 #endif
122 #else
123 #define MONO_HAS_CLANG_THREAD_SANITIZER 0
124 #endif
125
126 /* Used to tell Clang's ThreadSanitizer to not report data races that occur within a certain function */
127 #if MONO_HAS_CLANG_THREAD_SANITIZER
128 #define MONO_NO_SANITIZE_THREAD __attribute__ ((no_sanitize("thread")))
129 #else
130 #define MONO_NO_SANITIZE_THREAD
131 #endif
132
133 #endif /* __UTILS_MONO_COMPILER_H__*/
134