aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bug.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/bug.h')
-rw-r--r--include/linux/bug.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/include/linux/bug.h b/include/linux/bug.h
index 89fb91d0c929..73af37ca472c 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -2,6 +2,7 @@
2#define _LINUX_BUG_H 2#define _LINUX_BUG_H
3 3
4#include <asm/bug.h> 4#include <asm/bug.h>
5#include <linux/compiler.h>
5 6
6enum bug_trap_type { 7enum bug_trap_type {
7 BUG_TRAP_TYPE_NONE = 0, 8 BUG_TRAP_TYPE_NONE = 0,
@@ -43,25 +44,30 @@ struct pt_regs;
43 * @condition: the condition which the compiler should know is false. 44 * @condition: the condition which the compiler should know is false.
44 * 45 *
45 * If you have some code which relies on certain constants being equal, or 46 * If you have some code which relies on certain constants being equal, or
46 * other compile-time-evaluated condition, you should use BUILD_BUG_ON to 47 * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to
47 * detect if someone changes it. 48 * detect if someone changes it.
48 * 49 *
49 * The implementation uses gcc's reluctance to create a negative array, but 50 * The implementation uses gcc's reluctance to create a negative array, but gcc
50 * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments 51 * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to
51 * to inline functions). So as a fallback we use the optimizer; if it can't 52 * inline functions). Luckily, in 4.3 they added the "error" function
52 * prove the condition is false, it will cause a link error on the undefined 53 * attribute just for this type of case. Thus, we use a negative sized array
53 * "__build_bug_on_failed". This error message can be harder to track down 54 * (should always create an error on gcc versions older than 4.4) and then call
54 * though, hence the two different methods. 55 * an undefined function with the error attribute (should always create an
56 * error on gcc 4.3 and later). If for some reason, neither creates a
57 * compile-time error, we'll still have a link-time error, which is harder to
58 * track down.
55 */ 59 */
56#ifndef __OPTIMIZE__ 60#ifndef __OPTIMIZE__
57#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 61#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
58#else 62#else
59extern int __build_bug_on_failed; 63#define BUILD_BUG_ON(condition) \
60#define BUILD_BUG_ON(condition) \ 64 do { \
61 do { \ 65 bool __cond = !!(condition); \
62 bool __cond = !!(condition); \ 66 extern void __build_bug_on_failed(void) \
63 ((void)sizeof(char[1 - 2 * __cond])); \ 67 __compiletime_error("BUILD_BUG_ON failed"); \
64 if (__cond) __build_bug_on_failed = 1; \ 68 if (__cond) \
69 __build_bug_on_failed(); \
70 ((void)sizeof(char[1 - 2 * __cond])); \
65 } while (0) 71 } while (0)
66#endif 72#endif
67 73