Go to the documentation of this file.
12 #ifndef TOR_COMPAT_COMPILER_H
13 #define TOR_COMPAT_COMPILER_H
18 #if defined(__MINGW32__) || defined(__MINGW64__)
27 #if defined(__has_feature)
28 # if __has_feature(address_sanitizer)
36 #ifndef NULL_REP_IS_ZERO_BYTES
37 #error "Your platform does not represent NULL as zero. We can't cope."
40 #ifndef DOUBLE_0_REP_IS_ZERO_BYTES
41 #error "Your platform does not represent 0.0 as zeros. We can't cope."
44 #if 'a'!=97 || 'z'!=122 || 'A'!=65 || ' '!=32
45 #error "It seems that you encode characters in something other than ASCII."
51 #ifdef __MINGW_PRINTF_FORMAT
52 #define PRINTF_FORMAT_ATTR __MINGW_PRINTF_FORMAT
54 #define PRINTF_FORMAT_ATTR printf
56 #ifdef __MINGW_SCANF_FORMAT
57 #define SCANF_FORMAT_ATTR __MINGW_SCANF_FORMAT
59 #define SCANF_FORMAT_ATTR scanf
64 #define CHECK_PRINTF(formatIdx, firstArg) \
65 __attribute__ ((format(PRINTF_FORMAT_ATTR, formatIdx, firstArg)))
67 #define CHECK_PRINTF(formatIdx, firstArg)
70 #define CHECK_SCANF(formatIdx, firstArg) \
71 __attribute__ ((format(SCANF_FORMAT_ATTR, formatIdx, firstArg)))
73 #define CHECK_SCANF(formatIdx, firstArg)
76 #if defined(HAVE_ATTR_FALLTHROUGH)
77 #define FALLTHROUGH __attribute__((fallthrough))
84 #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
92 # define PRAGMA_(x) _Pragma (#x)
94 # define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(clang diagnostic x)
96 # define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(GCC diagnostic x)
98 # if defined(__clang__) || GCC_VERSION >= 406
100 # define DISABLE_GCC_WARNING(warningopt) \
101 PRAGMA_DIAGNOSTIC_(push) \
102 PRAGMA_DIAGNOSTIC_(ignored warningopt)
103 # define ENABLE_GCC_WARNING(warningopt) \
104 PRAGMA_DIAGNOSTIC_(pop)
107 # define DISABLE_GCC_WARNING(warningopt) \
108 PRAGMA_DIAGNOSTIC_(ignored warningopt)
109 # define ENABLE_GCC_WARNING(warningopt) \
110 PRAGMA_DIAGNOSTIC_(warning warningopt)
114 # define DISABLE_GCC_WARNING(warning)
115 # define ENABLE_GCC_WARNING(warning)
120 #define inline __inline
124 #if defined(_MSC_VER)
126 #define __func__ __FUNCTION__
131 #ifndef HAVE_MACRO__func__
132 #ifdef HAVE_MACRO__FUNCTION__
133 #define __func__ __FUNCTION__
134 #elif HAVE_MACRO__FUNC__
135 #define __func__ __FUNC__
137 #define __func__ "???"
142 #ifdef ENUM_VALS_ARE_SIGNED
143 #define ENUM_BF(t) unsigned
153 #if defined(__GNUC__) && __GNUC__ >= 3
154 #define ATTR_NORETURN __attribute__((noreturn))
155 #define ATTR_CONST __attribute__((const))
156 #define ATTR_MALLOC __attribute__((malloc))
157 #define ATTR_NORETURN __attribute__((noreturn))
158 #define ATTR_WUR __attribute__((warn_unused_result))
159 #define ATTR_UNUSED __attribute__ ((unused))
168 #define PREDICT_LIKELY(exp) __builtin_expect(!!(exp), 1)
176 #define PREDICT_UNLIKELY(exp) __builtin_expect(!!(exp), 0)
178 #define ATTR_NORETURN
181 #define ATTR_NORETURN
184 #define PREDICT_LIKELY(exp) (exp)
185 #define PREDICT_UNLIKELY(exp) (exp)
189 #define STMT_NIL (void)0
193 #define STMT_VOID(a) while (0) { (void)(a); }
198 #define STMT_BEGIN (void) ({
200 #elif defined(sun) || defined(__sun__)
201 #define STMT_BEGIN if (1) {
202 #define STMT_END } else STMT_NIL
204 #define STMT_BEGIN do {
205 #define STMT_END } while (0)
226 #define STRUCT_VAR_P(st, off) ((void*) ( ((char*)(st)) + (off) ) )
237 #define SUBTYPE_P(p, subtype, basemember) \
238 ((void*) ( ((char*)(p)) - offsetof(subtype, basemember) ))
241 #define ARRAY_LENGTH(x) ((sizeof(x)) / sizeof(x[0]))
252 #define EAT_SEMICOLON \
253 struct dummy_semicolon_eater__
260 #if defined(__COVERITY__) || defined(__clang_analyzer__)
263 #define POSSIBLE(expr) ((expr) || getenv("STATIC_ANALYZER_DEADCODE_DUMMY_"))
265 #define POSSIBLE(expr) (expr)