Go to the documentation of this file.
12 #ifndef TOR_COMPAT_COMPILER_H
13 #define TOR_COMPAT_COMPILER_H
18 #if defined(__has_feature)
19 # if __has_feature(address_sanitizer)
27 #ifndef NULL_REP_IS_ZERO_BYTES
28 #error "Your platform does not represent NULL as zero. We can't cope."
31 #ifndef DOUBLE_0_REP_IS_ZERO_BYTES
32 #error "Your platform does not represent 0.0 as zeros. We can't cope."
35 #if 'a'!=97 || 'z'!=122 || 'A'!=65 || ' '!=32
36 #error "It seems that you encode characters in something other than ASCII."
41 #define CHECK_PRINTF(formatIdx, firstArg) \
42 __attribute__ ((format(printf, formatIdx, firstArg)))
44 #define CHECK_PRINTF(formatIdx, firstArg)
47 #define CHECK_SCANF(formatIdx, firstArg) \
48 __attribute__ ((format(scanf, formatIdx, firstArg)))
50 #define CHECK_SCANF(formatIdx, firstArg)
53 #if defined(HAVE_ATTR_FALLTHROUGH)
54 #define FALLTHROUGH __attribute__((fallthrough))
61 #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
69 # define PRAGMA_(x) _Pragma (#x)
71 # define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(clang diagnostic x)
73 # define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(GCC diagnostic x)
75 # if defined(__clang__) || GCC_VERSION >= 406
77 # define DISABLE_GCC_WARNING(warningopt) \
78 PRAGMA_DIAGNOSTIC_(push) \
79 PRAGMA_DIAGNOSTIC_(ignored warningopt)
80 # define ENABLE_GCC_WARNING(warningopt) \
81 PRAGMA_DIAGNOSTIC_(pop)
84 # define DISABLE_GCC_WARNING(warningopt) \
85 PRAGMA_DIAGNOSTIC_(ignored warningopt)
86 # define ENABLE_GCC_WARNING(warningopt) \
87 PRAGMA_DIAGNOSTIC_(warning warningopt)
91 # define DISABLE_GCC_WARNING(warning)
92 # define ENABLE_GCC_WARNING(warning)
97 #define inline __inline
101 #if defined(_MSC_VER)
103 #define __func__ __FUNCTION__
108 #ifndef HAVE_MACRO__func__
109 #ifdef HAVE_MACRO__FUNCTION__
110 #define __func__ __FUNCTION__
111 #elif HAVE_MACRO__FUNC__
112 #define __func__ __FUNC__
114 #define __func__ "???"
119 #ifdef ENUM_VALS_ARE_SIGNED
120 #define ENUM_BF(t) unsigned
130 #if defined(__GNUC__) && __GNUC__ >= 3
131 #define ATTR_NORETURN __attribute__((noreturn))
132 #define ATTR_CONST __attribute__((const))
133 #define ATTR_MALLOC __attribute__((malloc))
134 #define ATTR_NORETURN __attribute__((noreturn))
135 #define ATTR_WUR __attribute__((warn_unused_result))
136 #define ATTR_UNUSED __attribute__ ((unused))
145 #define PREDICT_LIKELY(exp) __builtin_expect(!!(exp), 1)
153 #define PREDICT_UNLIKELY(exp) __builtin_expect(!!(exp), 0)
155 #define ATTR_NORETURN
158 #define ATTR_NORETURN
161 #define PREDICT_LIKELY(exp) (exp)
162 #define PREDICT_UNLIKELY(exp) (exp)
166 #define STMT_NIL (void)0
170 #define STMT_VOID(a) while (0) { (void)(a); }
175 #define STMT_BEGIN (void) ({
177 #elif defined(sun) || defined(__sun__)
178 #define STMT_BEGIN if (1) {
179 #define STMT_END } else STMT_NIL
181 #define STMT_BEGIN do {
182 #define STMT_END } while (0)
194 #if defined(__MINGW32__) || defined(__MINGW64__)
207 #define STRUCT_VAR_P(st, off) ((void*) ( ((char*)(st)) + (off) ) )
218 #define SUBTYPE_P(p, subtype, basemember) \
219 ((void*) ( ((char*)(p)) - offsetof(subtype, basemember) ))
222 #define ARRAY_LENGTH(x) ((sizeof(x)) / sizeof(x[0]))
233 #define EAT_SEMICOLON \
234 struct dummy_semicolon_eater__
241 #if defined(__COVERITY__) || defined(__clang_analyzer__)
244 #define POSSIBLE(expr) ((expr) || getenv("STATIC_ANALYZER_DEADCODE_DUMMY_"))
246 #define POSSIBLE(expr) (expr)