LibC: Replace use of do/while in assert() with the ternary operator

It's a single expression, no do/while needed. This makes assert() work
with the comma operator (assert(foo), assert(bar), assert(baz)).
Found because exactly this is being used somewhere in the guts of LLVM.
This commit is contained in:
Linus Groh 2021-07-12 21:37:31 +01:00
commit 15d5c62915
Notes: sideshowbarker 2024-07-18 09:09:30 +09:00

View file

@ -15,10 +15,10 @@ __attribute__((noreturn)) void __assertion_failed(const char* msg);
# define __stringify_helper(x) # x
# define __stringify(x) __stringify_helper(x)
# define assert(expr) \
do { \
if (__builtin_expect(!(expr), 0)) \
__assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)); \
} while (0)
(__builtin_expect(!(expr), 0) \
? __assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)) \
: void(0))
#else
# define assert(expr) ((void)(0))
# define VERIFY_NOT_REACHED() _abort()