x86: mark BUG()s and assertion failures as terminal.
authorTim Deegan <tim@xen.org>
Thu, 19 Sep 2013 14:38:09 +0000 (15:38 +0100)
committerTim Deegan <tim@xen.org>
Thu, 19 Sep 2013 15:17:57 +0000 (16:17 +0100)
This helps avoid static analysis false-positives, and might lead to
better code density as the compiler knows it doesn't have to restore
spilled state &c.

Signed-off-by: Tim Deegan <tim@xen.org>
Acked-by: Keir Fraser <keir@xen.org>
xen/include/asm-x86/bug.h
xen/include/xen/compiler.h

index e5dd559407f6e730f6af2274bef4aa0f23eabbb9..956bfd231f2628e5aa3f83b2c723c76febfe91d9 100644 (file)
@@ -46,12 +46,17 @@ struct bug_frame {
 
 
 #define WARN() BUG_FRAME(BUGFRAME_warn, __LINE__, __FILE__, 0, NULL)
-#define BUG()  BUG_FRAME(BUGFRAME_bug,  __LINE__, __FILE__, 0, NULL)
+#define BUG() do {                                              \
+    BUG_FRAME(BUGFRAME_bug,  __LINE__, __FILE__, 0, NULL);      \
+    unreachable();                                              \
+} while (0)
 
 #define run_in_exception_handler(fn) BUG_FRAME(BUGFRAME_run_fn, 0, fn, 0, NULL)
 
-#define assert_failed(msg)                                      \
-    BUG_FRAME(BUGFRAME_assert, __LINE__, __FILE__, 1, msg)
+#define assert_failed(msg) do {                                 \
+    BUG_FRAME(BUGFRAME_assert, __LINE__, __FILE__, 1, msg);     \
+    unreachable();                                              \
+} while (0)
 
 extern const struct bug_frame __start_bug_frames[],
                               __stop_bug_frames_0[],
index 7009a0930be6dee74e3ffa4fd2516004792e16bf..7d6805c415181b6327f1e1cdce2e4497f8821b0a 100644 (file)
 #define always_inline __inline__ __attribute__ ((always_inline))
 #define noinline      __attribute__((noinline))
 
+#if (!defined(__clang__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 5))
+#define unreachable() do {} while (1)
+#else
+#define unreachable() __builtin_unreachable()
+#endif
+
 #ifdef __clang__
 /* Clang can replace some vars with new automatic ones that go in .data;
  * mark all explicit-segment vars 'used' to prevent that. */