diff options
author | David Daney <ddaney@caviumnetworks.com> | 2008-11-20 20:26:36 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2008-11-24 11:35:07 -0500 |
commit | 8ec2e24356e63dc298c6040557faf396410907ac (patch) | |
tree | 77615c090cec2a726a31618e66aaac7dd10a33b1 /arch/mips/include/asm/bug.h | |
parent | ed313489badef16d700f5a3be50e8fd8f8294bc8 (diff) |
MIPS: Make BUG() __noreturn.
Often we do things like put BUG() in the default clause of a case
statement. Since it was not declared __noreturn, this could sometimes
lead to bogus compiler warnings that variables were used
uninitialized.
There is a small problem in that we have to put a magic while(1); loop to
fool GCC into really thinking it is noreturn. This makes the new
BUG() function 3 instructions long instead of just 1, but I think it
is worth it as it is now unnecessary to do extra work to silence the
'used uninitialized' warnings.
I also re-wrote BUG_ON so that if it is given a constant condition, it
just does BUG() instead of loading a constant value in to a register
and testing it.
Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/include/asm/bug.h')
-rw-r--r-- | arch/mips/include/asm/bug.h | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/arch/mips/include/asm/bug.h b/arch/mips/include/asm/bug.h index 7eb63de808bc..08ea46863fe5 100644 --- a/arch/mips/include/asm/bug.h +++ b/arch/mips/include/asm/bug.h | |||
@@ -7,20 +7,31 @@ | |||
7 | 7 | ||
8 | #include <asm/break.h> | 8 | #include <asm/break.h> |
9 | 9 | ||
10 | #define BUG() \ | 10 | static inline void __noreturn BUG(void) |
11 | do { \ | 11 | { |
12 | __asm__ __volatile__("break %0" : : "i" (BRK_BUG)); \ | 12 | __asm__ __volatile__("break %0" : : "i" (BRK_BUG)); |
13 | } while (0) | 13 | /* Fool GCC into thinking the function doesn't return. */ |
14 | while (1) | ||
15 | ; | ||
16 | } | ||
14 | 17 | ||
15 | #define HAVE_ARCH_BUG | 18 | #define HAVE_ARCH_BUG |
16 | 19 | ||
17 | #if (_MIPS_ISA > _MIPS_ISA_MIPS1) | 20 | #if (_MIPS_ISA > _MIPS_ISA_MIPS1) |
18 | 21 | ||
19 | #define BUG_ON(condition) \ | 22 | static inline void __BUG_ON(unsigned long condition) |
20 | do { \ | 23 | { |
21 | __asm__ __volatile__("tne $0, %0, %1" \ | 24 | if (__builtin_constant_p(condition)) { |
22 | : : "r" (condition), "i" (BRK_BUG)); \ | 25 | if (condition) |
23 | } while (0) | 26 | BUG(); |
27 | else | ||
28 | return; | ||
29 | } | ||
30 | __asm__ __volatile__("tne $0, %0, %1" | ||
31 | : : "r" (condition), "i" (BRK_BUG)); | ||
32 | } | ||
33 | |||
34 | #define BUG_ON(C) __BUG_ON((unsigned long)(C)) | ||
24 | 35 | ||
25 | #define HAVE_ARCH_BUG_ON | 36 | #define HAVE_ARCH_BUG_ON |
26 | 37 | ||