NAME
NO_SANITIZE_ALIGNMENT,
NO_SANITIZE_UNDEFINED,
NO_SANITIZE_SIGNED_INTEGER_OVERFLOW,
NO_SANITIZE_UNSIGNED_INTEGER_OVERFLOW,
ALLOC_SIZE, RETURNS_NONNULL,
FALLTHROUGH, UNREACHABLE,
UNUSED, NDEBUG_UNUSED,
FP, PRAGMA,
STATIC_ASSERT, UNSAFE_CAST,
countof —
compiler macros
SYNOPSIS
#include
<libks/compiler.h>
__attribute__((NO_SANITIZE_ALIGNMENT))
__attribute__((NO_SANITIZE_UNDEFINED))
__attribute__((NO_SANITIZE_SIGNED_INTEGER_OVERFLOW))
__attribute__((NO_SANITIZE_UNSIGNED_INTEGER_OVERFLOW))
__attribute__((ALLOC_SIZE(position,
...)))
__attribute__((RETURNS_NONNULL))
FALLTHROUGH;
UNREACHABLE;
UNUSED(variable);
NDEBUG_UNUSED(variable);
FP(invariant,
...);
PRAGMA(pragma);
STATIC_ASSERT(expression,
message);
UNSAFE_CAST(type,
variable);
countof(variable);
DESCRIPTION
The compiler macros can be used to instruct the compiler about certain properties of the source code.
The NO_SANITIZE_ALIGNMENT macro is
intended to be used as an __attribute__ argument applicable to functions,
instructing the compiler to omit the alignment sanitizer.
The NO_SANITIZE_UNDEFINED macro is
intended to be used as an __attribute__ argument applicable to functions,
instructing the compiler to omit the undefined behavior sanitizer.
The NO_SANITIZE_SIGNED_INTEGER_OVERFLOW
macro is intended to be used as an __attribute__ argument applicable to
functions, instructing the compiler to omit the signed integer overflow
sanitizer.
The NO_SANITIZE_UNSIGNED_INTEGER_OVERFLOW
macro is intended to be used as an __attribute__ argument applicable to
functions, instructing the compiler to omit the unsigned integer overflow
sanitizer.
The ALLOC_SIZE macro is intended to be
used as an __attribute__ argument applicable to functions returning a
pointer to memory whose size is given by the function argument at the
one-based position.
The RETURNS_NONNULL macro is intended to
be used as an __attribute__ argument applicable to functions returning a
pointer that cannot be NULL.
The FALLTHROUGH macro annotates a switch
case as intentionally continuing execution to the next case.
The UNREACHABLE macro informs the compiler
that the current statement is unreachable.
The
UNUSED()
macro annotates variable as being unused.
The
NDEBUG_UNUSED()
macro annotates variable as being unused if
NDEBUG is defined.
The
FP() macro
mitigates static analyzer false positives by making the
invariant observable. One or more annotations may be
supplied which are discarded. Expands to nothing if
NDEBUG is defined.
FP(ptr != NULL, cppcheck, nullPointer);
The
PRAGMA()
macro expands to the
_Pragma()
operator if supported. Otherwise, it expands to nothing.
The
STATIC_ASSERT()
macro ensures expression evaluates non-zero at compile
time.
The
UNSAFE_CAST()
macro performs an unsafe cast, tricking the compiler into not emitting a
warning or error.
The
countof()
macro returns the number of elements in variable which
is required to be an array.
AUTHORS
Anton Lindqvist <anton@basename.se>