HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #if (__cplusplus >= 201402) || (defined(_MSC_VER) && _MSVC_LANG >= 201402)
32  #define SYS_HAS_CXX14 1
33 #else
34  #define SYS_HAS_CXX14 0
35 #endif
36 
37 // Token concatenation
38 #define SYS_CONCAT(a, b) SYS_CONCAT_(a, b)
39 #define SYS_CONCAT_(a, b) a ## b
40 
41 #define SYS_TO_STRING_(a) # a
42 #define SYS_TO_STRING(a) SYS_TO_STRING_(a)
43 
44 // Handy macro to add warnings (for fix-me's etc.)
45 #if defined(_MSC_VER)
46 #define SYS_MESSAGE(desc) __pragma(message(__FILE__ "(" SYS_TO_STRING(__LINE__) ") : Warning: " #desc))
47 #else
48 #define SYS_MESSAGE(__msg__) _Pragma(SYS_TO_STRING(message __msg__))
49 #endif
50 
51 // MSVC 2012 does not define the 'noexcept' keyword.
52 #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 180021114
53 #define SYS_NOEXCEPT
54 #else
55 #define SYS_NOEXCEPT noexcept
56 #endif
57 
58 // Define "explicit" for C++11 safe-bool operator
59 #if (__cplusplus >= 201103) || (_MSC_VER >= 1800)
60  #define SYS_SAFE_BOOL explicit
61 #else
62  #define SYS_SAFE_BOOL
63 #endif
64 
65 // Define the [[fallthrough]] and [[maybe_unused]] attributes.
66 #if defined(__has_cpp_attribute)
67  #if __has_cpp_attribute(fallthrough) == 201603
68  #define SYS_FALLTHROUGH [[fallthrough]]
69  #endif
70  #if __has_cpp_attribute(maybe_unused) == 201603
71  #define SYS_MAYBE_UNUSED [[maybe_unused]]
72  #endif
73 #endif
74 #if !defined(SYS_FALLTHROUGH)
75  #define SYS_FALLTHROUGH
76 #endif
77 #if !defined(SYS_MAYBE_UNUSED)
78  #define SYS_MAYBE_UNUSED
79 #endif
80 
81 // Apple dropped the ball on implementing C++11 thread_local in clang on OSX.
82 // Cited reason was that they thought they could do better than previous
83 // implementation, but then never did.
84 // See: https://devforums.apple.com/message/1079348#1079348
85 #if !(defined(__APPLE__) && defined(__clang__))
86  #define SYS_THREAD_LOCAL thread_local
87 #else
88  #define SYS_THREAD_LOCAL __thread
89 #endif
90 
91 // Instruct the compiler to assume that the expression given will be true and
92 // use that information to guide optimizations.
93 #if defined(_MSC_VER)
94  #define SYS_ASSUME(EXPR) __assume(EXPR)
95 #elif defined(__clang__)
96  #if __has_builtin(__builtin_assume)
97  #define SYS_ASSUME(EXPR) __builtin_assume(EXPR)
98  #else
99  #define SYS_ASSUME(EXPR) if (!(EXPR)) __builtin_unreachable()
100  #endif
101 #else
102  #define SYS_ASSUME(EXPR) if (!(EXPR)) __builtin_unreachable()
103 #endif
104 
105 // Defines to disable compiler sanitizer checks
106 #if defined(__has_feature)
107  #if __has_feature(thread_sanitizer)
108  #define SYS_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
109  #endif
110  #if __has_feature(memory_sanitizer)
111  #define SYS_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
112  #endif
113  #if __has_feature(address_sanitizer)
114  #define SYS_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
115  #endif
116 #endif
117 #if !defined(SYS_NO_SANITIZE_THREAD)
118  #define SYS_NO_SANITIZE_THREAD
119 #endif
120 #if !defined(SYS_NO_SANITIZE_MEMORY)
121  #define SYS_NO_SANITIZE_MEMORY
122 #endif
123 #if !defined(SYS_NO_SANITIZE_ADDRESS)
124  #define SYS_NO_SANITIZE_ADDRESS
125 #endif
126 
127 #endif // __SYS_COMPILER_H_INCLUDED__