]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
bug.h: Prevent double evaulation of in BUILD_BUG_ON
authorDaniel Santos <daniel.santos@pobox.com>
Wed, 20 Feb 2013 02:13:30 +0000 (13:13 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 20 Feb 2013 05:52:00 +0000 (16:52 +1100)
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 <daniel.santos@pobox.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Rientjes <rientjes@google.com>
Cc: Joe Perches <joe@perches.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/bug.h

index 27d404f91b3e990a71ad41551669d8bcea8ed3f1..0d75762cd41585ec6c85b13d592787b1c737de51 100644 (file)
@@ -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