Skip to content

Commit

Permalink
bug.h: prevent double evaulation of `condition' in BUILD_BUG_ON
Browse files Browse the repository at this point in the history
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 <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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Daniel Santos authored and Linus Torvalds committed Feb 22, 2013
1 parent ca623c9 commit 1d6a0d1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/linux/bug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down

0 comments on commit 1d6a0d1

Please sign in to comment.