Version: SMASH-3.4
macros.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015,2017-2018,2020,2022-2023,2026
3  * SMASH Team
4  */
5 #ifndef SRC_INCLUDE_SMASH_MACROS_H_
6 #define SRC_INCLUDE_SMASH_MACROS_H_
7 
8 /* support for gcc branch prediction */
9 #ifdef __GNUC__
10 #define likely(x) __builtin_expect((x), 1)
11 #define unlikely(x) __builtin_expect((x), 0)
12 #else
13 /// Tell the branch predictor that this expression is likely true.
14 #define likely(x) (x)
15 /// Tell the branch predictor that this expression is likely false.
16 #define unlikely(x) (x)
17 #endif
18 
19 /// Mark as deprecated, generating compiler warnings when used.
20 #define SMASH_DEPRECATED(msg) __attribute__((deprecated(msg)))
21 
22 /* Handy macros to suppress GNU diagnostics */
23 #if defined(__GNUC__) && !defined(__clang__)
24 
25 /// Helper macros to turn macro arguments into _Pragma strings
26 #define DO_PRAGMA_(x) _Pragma(#x)
27 
28 /// Extra level of indirection to allow expansion of the argument
29 #define DO_PRAGMA(x) DO_PRAGMA_(x)
30 
31 /**
32  * Safe suppression of GCC warnings for specific headers. This is needed for
33  * some headers that trigger warnings that we cannot fix (e.g. from third-party
34  * libraries, like Eigen3) and that we do not want to ignore globally. Example
35  * usage:
36  *
37  * \code
38  * GCC_IGNORE_BEGIN("-Wnull-dereference")
39  * GCC_IGNORE_ALSO("-Wcast-align")
40  * #include <Eigen/Dense>
41  * GCC_IGNORE_END()
42  * \endcode
43  *
44  * Note that at the moment this is restricted to the GNU compiler and other
45  * compilers are ignored. If future needs arise, this can be extended to support
46  * other compilers as well.
47  */
48 #define GCC_IGNORE_BEGIN(warning) \
49  DO_PRAGMA(GCC diagnostic push) \
50  DO_PRAGMA(GCC diagnostic ignored warning)
51 
52 /// Add more warnings while still inside the block
53 #define GCC_IGNORE_ALSO(warning) DO_PRAGMA(GCC diagnostic ignored warning)
54 
55 /// End ignoring warnings
56 #define GCC_IGNORE_END() DO_PRAGMA(GCC diagnostic pop)
57 
58 #else
59 
60 /// Non-GCC compilers: fallback empty macro
61 #define GCC_IGNORE_BEGIN(warning)
62 
63 /// Non-GCC compilers: fallback empty macro
64 #define GCC_IGNORE_ALSO(warning)
65 
66 /// Non-GCC compilers: fallback empty macro
67 #define GCC_IGNORE_END()
68 
69 #endif
70 
71 #endif // SRC_INCLUDE_SMASH_MACROS_H_