LibC: Hint the compiler that assertions rarely fail
Also, rewrite the macro to expand to an if statement instead of a weird ternary operator with a (void)0 banch.
This commit is contained in:
parent
b319aca81a
commit
1b36ddce1d
Notes:
sideshowbarker
2024-07-19 07:09:50 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/1b36ddce1d1 Pull-request: https://github.com/SerenityOS/serenity/pull/2024 Reviewed-by: https://github.com/awesomekling
1 changed files with 5 additions and 1 deletions
|
@ -34,7 +34,11 @@ __BEGIN_DECLS
|
|||
__attribute__((noreturn)) void __assertion_failed(const char* msg);
|
||||
# define __stringify_helper(x) # x
|
||||
# define __stringify(x) __stringify_helper(x)
|
||||
# define assert(expr) ((expr) ? (void)0 : __assertion_failed(# expr "\n" __FILE__ ":" __stringify(__LINE__)));
|
||||
# define assert(expr) \
|
||||
do { \
|
||||
if (__builtin_expect(!(expr), 0)) \
|
||||
__assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)); \
|
||||
} while (0)
|
||||
# define ASSERT_NOT_REACHED() assert(false)
|
||||
#else
|
||||
# define assert(expr)
|
||||
|
|
Loading…
Add table
Reference in a new issue