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
8
debug.h
8
debug.h
|
|
@ -2,12 +2,11 @@
|
||||||
|
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
||||||
#ifdef NDEBUG
|
|
||||||
#define BUG(...) UNREACHABLE()
|
|
||||||
#else
|
|
||||||
#define BUG(...) bug(__FILE__, __LINE__, __func__, __VA_ARGS__)
|
#define BUG(...) bug(__FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#define xassert(x)
|
||||||
|
#else
|
||||||
#define xassert(x) do { \
|
#define xassert(x) do { \
|
||||||
IGNORE_WARNING("-Wtautological-compare") \
|
IGNORE_WARNING("-Wtautological-compare") \
|
||||||
if (unlikely(!(x))) { \
|
if (unlikely(!(x))) { \
|
||||||
|
|
@ -15,6 +14,7 @@
|
||||||
} \
|
} \
|
||||||
UNIGNORE_WARNINGS \
|
UNIGNORE_WARNINGS \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef static_assert
|
#ifndef static_assert
|
||||||
#if __STDC_VERSION__ >= 201112L
|
#if __STDC_VERSION__ >= 201112L
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue