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))
82#if defined(HAVE_ATTR_NONSTRING)
83#define NONSTRING __attribute__((nonstring))
90#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
98# define PRAGMA_(x) _Pragma (#x)
100# define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(clang diagnostic x)
102# define PRAGMA_DIAGNOSTIC_(x) PRAGMA_(GCC diagnostic x)
104# if defined(__clang__) || GCC_VERSION >= 406
106# define DISABLE_GCC_WARNING(warningopt) \
107 PRAGMA_DIAGNOSTIC_(push) \
108 PRAGMA_DIAGNOSTIC_(ignored warningopt)
109# define ENABLE_GCC_WARNING(warningopt) \
110 PRAGMA_DIAGNOSTIC_(pop)
113# define DISABLE_GCC_WARNING(warningopt) \
114 PRAGMA_DIAGNOSTIC_(ignored warningopt)
115# define ENABLE_GCC_WARNING(warningopt) \
116 PRAGMA_DIAGNOSTIC_(warning warningopt)
120# define DISABLE_GCC_WARNING(warning)
121# define ENABLE_GCC_WARNING(warning)
126#define inline __inline
132#define __func__ __FUNCTION__
137#ifndef HAVE_MACRO__func__
138#ifdef HAVE_MACRO__FUNCTION__
139#define __func__ __FUNCTION__
140#elif HAVE_MACRO__FUNC__
141#define __func__ __FUNC__
143#define __func__ "???"
148#ifdef ENUM_VALS_ARE_SIGNED
149#define ENUM_BF(t) unsigned
159#if defined(__GNUC__) && __GNUC__ >= 3
160#define ATTR_NORETURN __attribute__((noreturn))
161#define ATTR_CONST __attribute__((const))
162#define ATTR_MALLOC __attribute__((malloc))
163#define ATTR_NORETURN __attribute__((noreturn))
164#define ATTR_WUR __attribute__((warn_unused_result))
165#define ATTR_UNUSED __attribute__ ((unused))
174#define PREDICT_LIKELY(exp) __builtin_expect(!!(exp), 1)
182#define PREDICT_UNLIKELY(exp) __builtin_expect(!!(exp), 0)
190#define PREDICT_LIKELY(exp) (exp)
191#define PREDICT_UNLIKELY(exp) (exp)
195#define STMT_NIL (void)0
199#define STMT_VOID(a) while (0) { (void)(a); }
204#define STMT_BEGIN (void) ({
206#elif defined(sun) || defined(__sun__)
207#define STMT_BEGIN if (1) {
208#define STMT_END } else STMT_NIL
210#define STMT_BEGIN do {
211#define STMT_END } while (0)
232#define STRUCT_VAR_P(st, off) ((void*) ( ((char*)(st)) + (off) ) )
243#define SUBTYPE_P(p, subtype, basemember) \
244 ((void*) ( ((char*)(p)) - offsetof(subtype, basemember) ))
247#define ARRAY_LENGTH(x) ((sizeof(x)) / sizeof(x[0]))
258#define EAT_SEMICOLON \
259 struct dummy_semicolon_eater__
266#if defined(__COVERITY__) || defined(__clang_analyzer__)
269#define POSSIBLE(expr) ((expr) || getenv("STATIC_ANALYZER_DEADCODE_DUMMY_"))
271#define POSSIBLE(expr) (expr)