Skip to contentSkip to conversation

Use __builtin_trap() to indicate that BUG() never returns

PATCH New Michael Ellerman 1 participant 1 message Sep 21, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use __builtin_trap() to indicate that BUG() never returns

By using __builtin_trap() in BUG() we tell the compiler that we don't expect the code below to be executed, and in certain circumstances this allows the compiler to elide that code altogether.

In fact it works so well that we have to put the bug section stuff before the __builtin_trap() or else it isn't generated at all.

Tested on P5 LPAR, line numbers etc. all OK.

---

 include/asm-powerpc/bug.h |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
include/asm-powerpc/bug.h +5 -4
Index: to-merge/include/asm-powerpc/bug.h
===================================================================
@@ -37,12 +37,13 @@ struct bug_entry *find_bug(unsigned long
  */
 
 #define BUG() do {							 \
-	__asm__ __volatile__(						 \
-		"1:	twi 31,0,0\n"					 \
+       __asm__ __volatile__(                                            \
 		".section __bug_table,\"a\"\n"				 \
-		"\t"PPC_LONG"	1b,%0,%1,%2\n"				 \
-		".previous"						 \
+		"\t"PPC_LONG"	1f,%0,%1,%2\n"				 \
+		".previous\n"						 \
+                "1:     "                                           \
 		: : "i" (__LINE__), "i" (__FILE__), "i" (__FUNCTION__)); \
+       __builtin_trap();                                                \
 } while (0)
 
 #define BUG_ON(x) do {						\