[PATCH 5/5] debug: BUILD_BUG_ON: error on non-const expressions

From: Boaz Harrosh
Date: Mon Sep 01 2008 - 09:28:54 EST


From: Rusty Russell <rusty@xxxxxxxxxxxxxxx>

Fix BUILD_BUG_ON to not silently drop non-compile-time
visible expressions.

Signed-off-by: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
Signed-off-by: Boaz Harrosh <bharrosh@xxxxxxxxxxx>
CC: Ingo Molnar <mingo@xxxxxxx>
CC: Alexey Dobriyan <adobriyan@xxxxxxxxx>
CC: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
CC: Theodore Tso <tytso@xxxxxxx>
CC: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
CC: Jan Beulich <jbeulich@xxxxxxxxxx>
CC: David S. Miller <davem@xxxxxxxxxxxxx>
CC: Ivo van Doorn <IvDoorn@xxxxxxxxx>
CC: John W. Linville <linville@xxxxxxxxxxxxx>
---
include/linux/compiler.h | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 90fa975..f677ab9 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -195,7 +195,10 @@ extern void __chk_io_ptr(const volatile void __iomem *);
#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))

/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+#define BUILD_BUG_ON(condition) \
+do { \
+ static struct { char arr[1 - 2*!!(condition)]; } x __maybe_unused;\
+} while(0)

/* Force a compilation error if condition is true, but also produce a
result (of value 0 and type size_t), so the expression can be used
--
1.5.6.rc1.5.gadf6


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/