[POWERPC] mark BUG() as noreturn

Stephen Rothwell sfr at canb.auug.org.au
Thu Sep 21 14:55:22 EST 2006


>From an idea from Michael Ellerman.

We finish the BUG() macro with a call to a function marked with attribute
"noreturn" so that the compiler will know that BUG() and BUG_ON()
(with a constant, non-zero argument) will not return.

Signed-off-by: Stephen Rothwell <sfr at canb.auug.org.au>
---
 include/asm-powerpc/bug.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

-- 
Cheers,
Stephen Rothwell                    sfr at canb.auug.org.au

diff --git a/include/asm-powerpc/bug.h b/include/asm-powerpc/bug.h
index f44b529..cf5c460 100644
--- a/include/asm-powerpc/bug.h
+++ b/include/asm-powerpc/bug.h
@@ -31,6 +31,16 @@ #define BUG_WARNING_TRAP	0x1000000
 #ifdef CONFIG_BUG
 
 /*
+ * This is so that we can tell the compiler that BUG() and
+ * BUG_ON() with a constant non-zero argument does not return.
+ */
+static inline void __attribute__((noreturn)) __bug_does_not_return(void)
+{
+	while (1)
+		/* do nothing */;
+}
+
+/*
  * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
  * optimisations. However depending on the complexity of the condition
  * some compiler versions may not produce optimal results.
@@ -43,6 +53,7 @@ #define BUG() do {							 \
 		"\t"PPC_LONG"	1b,%0,%1,%2\n"				 \
 		".previous"						 \
 		: : "i" (__LINE__), "i" (__FILE__), "i" (__FUNCTION__)); \
+		__bug_does_not_return();				 \
 } while (0)
 
 #define BUG_ON(x) do {						\
-- 
1.4.2.1




More information about the Linuxppc-dev mailing list