1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

AK: Add ASSERT() and ASSERT_NOT_REACHED() for debug-only assertions

Let's move towards using these for things that are "nice to check in
debug builds, but not essential".
This commit is contained in:
Andreas Kling 2024-07-09 14:21:34 +02:00 committed by Andreas Kling
parent f76f84d687
commit df18a76ad2
Notes: sideshowbarker 2024-07-17 05:41:34 +09:00
2 changed files with 33 additions and 0 deletions

View file

@ -20,3 +20,15 @@ static constexpr bool TODO = false;
#define TODO_RISCV64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#define TODO_PPC64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#define TODO_PPC() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#ifdef NDEBUG
extern "C" __attribute__((noreturn)) void ak_assertion_failed(char const*);
# define ASSERT(expr) \
(__builtin_expect(!(expr), 0) \
? ak_assertion_failed(#expr " at " __FILE__ ":" __stringify(__LINE__)) \
: (void)0)
# define ASSERT_NOT_REACHED ASSERT(false) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#else
# define ASSERT(expr)
# define ASSERT_NOT_REACHED() __builtin_unreachable()
#endif