HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SYS_Compiler.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_Compiler.h (SYS Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __SYS_COMPILER_H_INCLUDED__
12 #define __SYS_COMPILER_H_INCLUDED__
13 
14 #if defined(__GNUC__)
15  #define SYS_IS_GCC_GE(MAJOR, MINOR) \
16  (__GNUC__ > MAJOR || (__GNUC__ == MAJOR && __GNUC_MINOR__ >= MINOR))
17  #define SYS_IS_GCC_EQ(MAJOR, MINOR) \
18  (__GNUC__ == MAJOR && __GNUC_MINOR__ == MINOR)
19 #else
20  #define SYS_IS_GCC_GE(MAJOR, MINOR) 0
21  #define SYS_IS_GCC_EQ(MAJOR, MINOR) 0
22 #endif
23 
24 #if defined(__clang__)
25  #define SYS_IS_CLANG_GE(MAJOR, MINOR) \
26  (__clang_major__ > MAJOR || (__clang_major__ == MAJOR && __clang_minor__ >= MINOR))
27 #else
28  #define SYS_IS_CLANG_GE(MAJOR, MINOR) 0
29 #endif
30 
31 // Token concatenation
32 #define SYS_CONCAT(a, b) SYS_CONCAT_(a, b)
33 #define SYS_CONCAT_(a, b) a ## b
34 
35 #define SYS_TO_STRING_(a) # a
36 #define SYS_TO_STRING(a) SYS_TO_STRING_(a)
37 
38 // Handy macro to add warnings (for fix-me's etc.)
39 #if defined(_MSC_VER)
40 #define SYS_MESSAGE(desc) __pragma(message(__FILE__ "(" SYS_TO_STRING(__LINE__) ") : Warning: " #desc))
41 #else
42 #define SYS_MESSAGE(__msg__) _Pragma(SYS_TO_STRING(message __msg__))
43 #endif
44 
45 // MSVC 2012 does not define the 'noexcept' keyword.
46 #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 180021114
47 #define SYS_NOEXCEPT
48 #else
49 #define SYS_NOEXCEPT noexcept
50 #endif
51 
52 // Define "explicit" for C++11 safe-bool operator
53 #if (__cplusplus >= 201103) || (_MSC_VER >= 1800)
54  #define SYS_SAFE_BOOL explicit
55 #else
56  #define SYS_SAFE_BOOL
57 #endif
58 
59 // Apple dropped the ball on implementing C++11 thread_local in clang on OSX.
60 // Cited reason was that they thought they could do better than previous
61 // implementation, but then never did.
62 // See: https://devforums.apple.com/message/1079348#1079348
63 #if !(defined(__APPLE__) && defined(__clang__))
64  #define SYS_THREAD_LOCAL thread_local
65 #else
66  #define SYS_THREAD_LOCAL __thread
67 #endif
68 
69 // Instruct the compiler to assume that the expression given will be true and
70 // use that information to guide optimizations.
71 #if defined(_MSC_VER)
72  #define SYS_ASSUME(EXPR) __assume(EXPR)
73 #elif defined(__clang__)
74  #if __has_builtin(__builtin_assume)
75  #define SYS_ASSUME(EXPR) __builtin_assume(EXPR)
76  #else
77  #define SYS_ASSUME(EXPR) if (!(EXPR)) __builtin_unreachable()
78  #endif
79 #else
80  #define SYS_ASSUME(EXPR) if (!(EXPR)) __builtin_unreachable()
81 #endif
82 
83 // Defines to disable compiler sanitizer checks
84 #if defined(__has_feature)
85  #if __has_feature(thread_sanitizer)
86  #define SYS_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
87  #endif
88  #if __has_feature(memory_sanitizer)
89  #define SYS_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
90  #endif
91  #if __has_feature(address_sanitizer)
92  #define SYS_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
93  #endif
94 #endif
95 #if !defined(SYS_NO_SANITIZE_THREAD)
96  #define SYS_NO_SANITIZE_THREAD
97 #endif
98 #if !defined(SYS_NO_SANITIZE_MEMORY)
99  #define SYS_NO_SANITIZE_MEMORY
100 #endif
101 #if !defined(SYS_NO_SANITIZE_ADDRESS)
102  #define SYS_NO_SANITIZE_ADDRESS
103 #endif
104 
105 #endif // __SYS_COMPILER_H_INCLUDED__