From 1d6a0d19c85587581a364850b77f30446810a560 Mon Sep 17 00:00:00 2001 From: Daniel Santos Date: Thu, 21 Feb 2013 16:41:45 -0800 Subject: bug.h: prevent double evaulation of `condition' 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. [akpm@linux-foundation.org: tweak code layout] 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 Signed-off-by: Linus Torvalds --- include/linux/bug.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/linux/bug.h b/include/linux/bug.h index 27d404f91b3e..89fb91d0c929 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -59,9 +59,10 @@ 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; \ - } while(0) + bool __cond = !!(condition); \ + ((void)sizeof(char[1 - 2 * __cond])); \ + if (__cond) __build_bug_on_failed = 1; \ + } while (0) #endif /** -- cgit v1.2.3