Browse Source

LibC: Turn CRASH() into a function and add noreturn attribute

This way CRASH() can be used in functions that are themselves
marked as noreturn.
Gunnar Beutner 4 years ago
parent
commit
44486e8818
2 changed files with 9 additions and 4 deletions
  1. 6 0
      Userland/Libraries/LibC/assert.cpp
  2. 3 4
      Userland/Libraries/LibC/assert.h

+ 6 - 0
Userland/Libraries/LibC/assert.cpp

@@ -53,3 +53,9 @@ void __assertion_failed(const char* msg)
 }
 }
 #endif
 #endif
 }
 }
+
+void __crash()
+{
+    asm volatile("ud2");
+    __builtin_unreachable();
+}

+ 3 - 4
Userland/Libraries/LibC/assert.h

@@ -45,10 +45,9 @@ __attribute__((noreturn)) void __assertion_failed(const char* msg);
 #    define VERIFY_NOT_REACHED() CRASH()
 #    define VERIFY_NOT_REACHED() CRASH()
 #endif
 #endif
 
 
-#define CRASH()              \
-    do {                     \
-        asm volatile("ud2"); \
-    } while (0)
+__attribute__((noreturn)) void __crash();
+
+#define CRASH() __crash()
 #define VERIFY assert
 #define VERIFY assert
 #define TODO VERIFY_NOT_REACHED
 #define TODO VERIFY_NOT_REACHED