From 3a27efbe278b4a0e54e9c2a6f1f7c27c1e1327af Mon Sep 17 00:00:00 2001 From: Daniel Santos Date: Wed, 20 Feb 2013 13:13:30 +1100 Subject: [PATCH] bug.h: Prevent double evaulation of in BUILD_BUG_ON When calling BUILD_BUG_ON in an optimized build using gcc 4.3 and later, the condition will be evaulated twice, possibily with side-effects. This patch eliminates that error. Signed-off-by: Daniel Santos Cc: Andi Kleen Cc: Borislav Petkov Cc: David Rientjes Cc: Joe Perches Cc: Josh Triplett Cc: Paul Gortmaker Signed-off-by: Andrew Morton --- include/linux/bug.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/linux/bug.h b/include/linux/bug.h index 27d404f91b3e..0d75762cd415 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -59,8 +59,9 @@ struct pt_regs; extern int __build_bug_on_failed; #define BUILD_BUG_ON(condition) \ do { \ - ((void)sizeof(char[1 - 2*!!(condition)])); \ - if (condition) __build_bug_on_failed = 1; \ + bool __cond = !!(condition); \ + ((void)sizeof(char[1 - 2 * __cond])); \ + if (__cond) __build_bug_on_failed = 1; \ } while(0) #endif -- 2.39.5