From mboxrd@z Thu Jan 1 00:00:00 1970 From: danielfsantos@att.net Subject: [PATCH v5 6/9] bug.h: Prevent double evaulation of in BUILD_BUG_ON Date: Tue, 13 Nov 2012 16:13:38 -0600 Message-ID: <1352844821-18952-6-git-send-email-daniel.santos@pobox.com> References: <1352844568-18826-1-git-send-email-daniel.santos@pobox.com> Return-path: In-Reply-To: <1352844568-18826-1-git-send-email-daniel.santos@pobox.com> Sender: linux-kernel-owner@vger.kernel.org To: LKML , Andi Kleen , Andrea Arcangeli , Andrew Morton , Borislav Petkov , Christopher Li , Daniel Santos , David Daney , David Howells , Joe Perches , Josh Triplett , Konstantin Khlebnikov , linux-sparse@vger.kernel.org, Michel Lespinasse , Paul Gortmaker , Pavel Pisa , Peter Zijlstra , Steven Rostedt List-Id: linux-sparse@vger.kernel.org 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 --- include/linux/bug.h | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/linux/bug.h b/include/linux/bug.h index 1b2465d..ccd44ce 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -58,8 +58,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 -- 1.7.3.4