Common macros and compiler attributes/pragmas configuration. More...
Common macros and compiler attributes/pragmas configuration.
Definition in file compiler_hints.h.
Go to the source code of this file.
#define | NORETURN |
The NORETURN keyword tells the compiler to assume that the function cannot return. | |
#define | PURE |
The function has no effects except the return value and its return value depends only on the parameters and/or global variables. | |
#define | MAYBE_UNUSED |
tell the compiler something may be unused static functions, function arguments, local variables | |
#define | NO_SANITIZE_ARRAY |
Tell the compiler that this array should be ignored during sanitizing. | |
#define | UNREACHABLE() do { /* nothing */ } while (1) |
Tell the compiler that this line of code cannot be reached. | |
#define | WITHOUT_PEDANTIC(...) |
Disable -Wpedantic for the argument, but restore diagnostic settings afterwards. | |
#define | DECLARE_CONSTANT(identifier, const_expr) WITHOUT_PEDANTIC(enum { identifier = const_expr };) |
Declare a constant named identifier as anonymous enum that has the value const_expr . | |
#define | IS_CT_CONSTANT(expr) <IMPLEMENTATION> |
Check if given variable / expression is detected as compile time constant. | |
#define | likely(x) __builtin_expect((uintptr_t)(x), 1) |
Hint to the compiler that the condition x is likely taken. | |
#define | unlikely(x) __builtin_expect((uintptr_t)(x), 0) |
Hint to the compiler that the condition x is likely not taken. | |
#define | assume(cond) assert(cond) |
Behaves like an assert() , but tells the compiler that cond can never be false. | |
static unsigned | may_be_zero (unsigned n) |
Wrapper function to silence "comparison is always false due to limited
range of data type" type of warning when the warning is caused by a preprocessor configuration value that may be zero. | |
#define assume | ( | cond | ) | assert(cond) |
Behaves like an assert()
, but tells the compiler that cond
can never be false.
This allows the compiler to optimize the code accordingly even when NDEBUG
is set / with DEVELHELP=0
.
cond
being false will result in undefined behavior.
[in] | cond | Condition that is guaranteed to be true |
Definition at line 181 of file compiler_hints.h.
#define DECLARE_CONSTANT | ( | identifier, | |
const_expr | |||
) | WITHOUT_PEDANTIC(enum { identifier = const_expr };) |
Declare a constant named identifier
as anonymous enum
that has the value const_expr
.
This turns any expression that is constant and known at compile time into a formal compile time constant. This allows e.g. using non-formally but still constant expressions in static_assert()
.
Definition at line 126 of file compiler_hints.h.
#define IS_CT_CONSTANT | ( | expr | ) | <IMPLEMENTATION> |
Check if given variable / expression is detected as compile time constant.
This will return 0 if the used compiler does not support this
This allows providing two different implementations in C, with one being more efficient if constant folding is used.
Definition at line 142 of file compiler_hints.h.
#define likely | ( | x | ) | __builtin_expect((uintptr_t)(x), 1) |
Hint to the compiler that the condition x
is likely taken.
[in] | x | Condition that is likely taken |
x
Definition at line 157 of file compiler_hints.h.
#define MAYBE_UNUSED |
tell the compiler something may be unused static functions, function arguments, local variables
Definition at line 68 of file compiler_hints.h.
#define NO_SANITIZE_ARRAY |
Tell the compiler that this array should be ignored during sanitizing.
In special cases, e.g. XFA, the address sanitizer might interfere in a way that breaks the application. Use this macro to disable address sanitizing for a given variable. Currently only utilised by llvm.
Definition at line 83 of file compiler_hints.h.
#define NORETURN |
The NORETURN keyword tells the compiler to assume that the function cannot return.
Definition at line 40 of file compiler_hints.h.
#define PURE |
The function has no effects except the return value and its return value depends only on the parameters and/or global variables.
Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be.
Definition at line 55 of file compiler_hints.h.
#define unlikely | ( | x | ) | __builtin_expect((uintptr_t)(x), 0) |
Hint to the compiler that the condition x
is likely not taken.
[in] | x | Condition that is unlikely |
x
Definition at line 166 of file compiler_hints.h.
#define UNREACHABLE | ( | ) | do { /* nothing */ } while (1) |
Tell the compiler that this line of code cannot be reached.
Most useful in junction with NORETURN. Use this if the compiler cannot tell that e.g. an assembler instruction causes a longjmp, or a write causes a reboot.
Definition at line 96 of file compiler_hints.h.
#define WITHOUT_PEDANTIC | ( | ... | ) |
Disable -Wpedantic for the argument, but restore diagnostic settings afterwards.
... | The expression that -Wpendantic should not apply to |
This is particularly useful when declaring non-strictly conforming preprocessor macros, as the diagnostics need to be disabled where the macro is evaluated, not where the macro is declared.
Definition at line 110 of file compiler_hints.h.
|
inlinestatic |
Wrapper function to silence "comparison is always false due to limited range of data type" type of warning when the warning is caused by a preprocessor configuration value that may be zero.
[in] | n | Variable that may be zero |
n
Definition at line 192 of file compiler_hints.h.