mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-30 06:46:45 -04:00
Fix performance regression caused by xassert() macro
Before this commit, the xassert() macro still expanded to e.g.:
if (unlikely(!(cond)))
__builtin_unreachable();
...even when NDEBUG was set.
If `cond` happened to contain a function call that the compiler couldn't
prove to be side-effect free, this call would still have to be emitted
in the generated code, even when everything else could be optimized out.
This commit changes xassert() to be more in-keeping with the standard
assert() macro when NDEBUG is set; specifically, it causes the entire
statement to expand to nothing, which thus guarantees that any function
calls in the condition will be dropped, regardless of whether or not
they have side-effects.
This commit is contained in:
parent
1d9cd8cc04
commit
cb9c13800e
1 changed files with 12 additions and 12 deletions
24
debug.h
24
debug.h
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
#include "macros.h"
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define BUG(...) UNREACHABLE()
|
||||
#else
|
||||
#define BUG(...) bug(__FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
#endif
|
||||
#define BUG(...) bug(__FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
|
||||
#define xassert(x) do { \
|
||||
IGNORE_WARNING("-Wtautological-compare") \
|
||||
if (unlikely(!(x))) { \
|
||||
BUG("assertion failed: '%s'", #x); \
|
||||
} \
|
||||
UNIGNORE_WARNINGS \
|
||||
} while (0)
|
||||
#ifdef NDEBUG
|
||||
#define xassert(x)
|
||||
#else
|
||||
#define xassert(x) do { \
|
||||
IGNORE_WARNING("-Wtautological-compare") \
|
||||
if (unlikely(!(x))) { \
|
||||
BUG("assertion failed: '%s'", #x); \
|
||||
} \
|
||||
UNIGNORE_WARNINGS \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef static_assert
|
||||
#if __STDC_VERSION__ >= 201112L
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue