From 44486e881892d2d59591cf9943c20e4265c6442a Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 11 Apr 2021 18:22:48 +0200 Subject: [PATCH] LibC: Turn CRASH() into a function and add noreturn attribute This way CRASH() can be used in functions that are themselves marked as noreturn. --- Userland/Libraries/LibC/assert.cpp | 6 ++++++ Userland/Libraries/LibC/assert.h | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibC/assert.cpp b/Userland/Libraries/LibC/assert.cpp index d4f99a1a8701fc..2915d43962eb89 100644 --- a/Userland/Libraries/LibC/assert.cpp +++ b/Userland/Libraries/LibC/assert.cpp @@ -53,3 +53,9 @@ void __assertion_failed(const char* msg) } #endif } + +void __crash() +{ + asm volatile("ud2"); + __builtin_unreachable(); +} diff --git a/Userland/Libraries/LibC/assert.h b/Userland/Libraries/LibC/assert.h index 572a35632aea7e..3749e66c434b9e 100644 --- a/Userland/Libraries/LibC/assert.h +++ b/Userland/Libraries/LibC/assert.h @@ -45,10 +45,9 @@ __attribute__((noreturn)) void __assertion_failed(const char* msg); # define VERIFY_NOT_REACHED() CRASH() #endif -#define CRASH() \ - do { \ - asm volatile("ud2"); \ - } while (0) +__attribute__((noreturn)) void __crash(); + +#define CRASH() __crash() #define VERIFY assert #define TODO VERIFY_NOT_REACHED