Commit 1d6a0d19 authored by Daniel Santos's avatar Daniel Santos Committed by Linus Torvalds

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: default avatarDaniel 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ca623c91
...@@ -59,9 +59,10 @@ struct pt_regs; ...@@ -59,9 +59,10 @@ struct pt_regs;
extern int __build_bug_on_failed; extern int __build_bug_on_failed;
#define BUILD_BUG_ON(condition) \ #define BUILD_BUG_ON(condition) \
do { \ do { \
((void)sizeof(char[1 - 2*!!(condition)])); \ bool __cond = !!(condition); \
if (condition) __build_bug_on_failed = 1; \ ((void)sizeof(char[1 - 2 * __cond])); \
} while(0) if (__cond) __build_bug_on_failed = 1; \
} while (0)
#endif #endif
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment