diff options
author | Andreas Kling <kling@serenityos.org> | 2022-10-06 13:35:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-06 15:29:38 +0200 |
commit | da781e90c11e6b7ac645f0ce046f909d3d3118f5 (patch) | |
tree | feffb4549ad769ed6eb00de84ba032d62d0de8a3 /AK/Assertions.h | |
parent | 4fdfaff4ca506d239e632586f10c015311aeea11 (diff) | |
download | serenity-da781e90c11e6b7ac645f0ce046f909d3d3118f5.zip |
AK: Print VERIFY() error messages in release builds
Until now, VERIFY() failures would just cause a __builtin_trap() in
release builds, which made them a bit too harsh. This commit adds an
out-of-line helper function that prints the error before trapping.
Diffstat (limited to 'AK/Assertions.h')
-rw-r--r-- | AK/Assertions.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/AK/Assertions.h b/AK/Assertions.h index 648d9b9d49..ab628c14a6 100644 --- a/AK/Assertions.h +++ b/AK/Assertions.h @@ -13,9 +13,12 @@ # ifndef NDEBUG # define VERIFY assert # else -# define VERIFY(expr) \ - (__builtin_expect(!(expr), 0) \ - ? __builtin_trap() \ +# define __stringify_helper(x) # x +# define __stringify(x) __stringify_helper(x) +extern "C" __attribute__((noreturn)) void ak_verification_failed(char const*); +# define VERIFY(expr) \ + (__builtin_expect(!(expr), 0) \ + ? ak_verification_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)) \ : (void)0) # endif # define VERIFY_NOT_REACHED() VERIFY(false) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */ |