mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00: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:
parent
f76f84d687
commit
df18a76ad2
Notes:
sideshowbarker
2024-07-17 05:41:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/df18a76ad2 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/535 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/LucasChollet Reviewed-by: https://github.com/alimpfard
2 changed files with 33 additions and 0 deletions
|
@ -96,6 +96,27 @@ void ak_verification_failed(char const* message)
|
|||
else
|
||||
ERRORLN("VERIFICATION FAILED: {}", message);
|
||||
|
||||
#if defined(AK_HAS_BACKTRACE_HEADER)
|
||||
dump_backtrace();
|
||||
#endif
|
||||
__builtin_trap();
|
||||
}
|
||||
|
||||
void ak_assertion_failed(char const* message)
|
||||
{
|
||||
#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID)
|
||||
bool colorize_output = true;
|
||||
#elif defined(AK_OS_WINDOWS)
|
||||
bool colorize_output = false;
|
||||
#else
|
||||
bool colorize_output = isatty(STDERR_FILENO) == 1;
|
||||
#endif
|
||||
|
||||
if (colorize_output)
|
||||
ERRORLN("\033[31;1mASSERTION FAILED\033[0m: {}", message);
|
||||
else
|
||||
ERRORLN("ASSERTION FAILED: {}", message);
|
||||
|
||||
#if defined(AK_HAS_BACKTRACE_HEADER)
|
||||
dump_backtrace();
|
||||
#endif
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue