1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8 
9 /**
10  * @file
11  *
12  * @brief Macros to abstract compiler capabilities for the GCC toolchain
13  *
14  * @internal
15  * This file should never be included directly; instead, one should
16  * include toolchain.h which will pull in the file appropriate to
17  * the detected toolchain.
18  */
19 
20 #if defined(__GNUC__)
21 
22 #define SCP_FORMAT_STRING
23 #define SCP_FORMAT_STRING_ARGS(x,y)  __attribute__((format(printf, x, y)))
24 
25 #define __UNUSED __attribute__((__unused__))
26 #define __ALIGNED(x)  __attribute__((__aligned__(x)))
27 
28 #ifdef NO_RESTRICT_USE
29 #   define RESTRICT
30 #else
31 #   define RESTRICT  restrict
32 #endif
33 
34 #define ASSUME(x)
35 
36 #if defined(NDEBUG)
37 #	define Assertion(expr, msg, ...)  do {} while (false)
38 #else
39 /*
40  * NOTE: Assertion() can only use its proper functionality in compilers
41  * that support variadic macros.
42  */
43 #	define Assertion(expr, msg, ...)                                      \
44 		do {                                                              \
45 			if (!(expr)) {                                                \
46 				os::dialogs::AssertMessage(#expr, __FILE__, __LINE__, msg, ##__VA_ARGS__); \
47 			}                                                             \
48 		} while (false)
49 #endif
50 
51 /* C++11 Standard Detection */
52 #if !defined(HAVE_CXX11)
53 	/*
54 	 * For GCC with autotools, see AX_CXX_COMPiLE_STDCXX_11 macro in the
55 	 * file "configure.ac". This sets HAVE_CXX11 & -std=c++0x or -std=c++11
56 	 * as appropriate.
57 	 *
58 	 * TODO: Is anything else required here?
59 	 */
60 #endif
61 
62 #define SIZE_T_ARG    "%zu"
63 #define PTRDIFF_T_ARG "%zd"
64 
65 #define likely(x)    __builtin_expect((long) !!(x), 1L)
66 #define unlikely(x)  __builtin_expect((long) !!(x), 0L)
67 
68 #define USED_VARIABLE __attribute__((used))
69 
70 #if __GNUC__ >= 7
71 #define FALLTHROUGH [[fallthrough]]
72 #else
73 #define FALLTHROUGH
74 #endif
75 
76 #define CLANG_ANALYZER_NORETURN
77 
78 #ifndef NDEBUG
79 #define UNREACHABLE(msg, ...)                                                                                          \
80 	do {                                                                                                               \
81 		os::dialogs::Error(__FILE__, __LINE__, msg, ##__VA_ARGS__);                                                    \
82 	} while (false)
83 #else
84 #define UNREACHABLE(msg, ...) __builtin_unreachable()
85 #endif
86 
87 /**
88  * @brief Suppresses all warnings and allows to pop back to normal afterwards
89  */
90 #define PUSH_SUPPRESS_WARNINGS \
91 _Pragma("GCC diagnostic push") \
92 _Pragma("GCC diagnostic ignored \"-Wattributes\"") \
93 
94 /**
95  * @brief Restored previous warning settings
96  */
97 #define POP_SUPPRESS_WARNINGS \
98 _Pragma("GCC diagnostic pop")
99 
100 #endif
101