Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1768193Ab2KOPHM (ORCPT ); Thu, 15 Nov 2012 10:07:12 -0500 Received: from mail.skyhub.de ([78.46.96.112]:56470 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1768180Ab2KOPHJ (ORCPT ); Thu, 15 Nov 2012 10:07:09 -0500 Date: Thu, 15 Nov 2012 16:07:27 +0100 From: Borislav Petkov To: Daniel Santos Cc: LKML , Andi Kleen , Andrea Arcangeli , Andrew Morton , Christopher Li , 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 Subject: Re: [PATCH v5 6/9] bug.h: Prevent double evaulation of in BUILD_BUG_ON Message-ID: <20121115150726.GD4956@x1.osrc.amd.com> Mail-Followup-To: Borislav Petkov , Daniel Santos , LKML , Andi Kleen , Andrea Arcangeli , Andrew Morton , Christopher Li , 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 References: <1352844568-18826-1-git-send-email-daniel.santos@pobox.com> <1352844821-18952-6-git-send-email-daniel.santos@pobox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1352844821-18952-6-git-send-email-daniel.santos@pobox.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1431 Lines: 45 On Tue, Nov 13, 2012 at 04:13:38PM -0600, danielfsantos@att.net wrote: > 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)])); \ No need for the !!(__cond) here because you've done it in the line above. IOW, bool __cond = !!(condition); ((void)sizeof(char[1 - 2 * __cond])); which is even a bit more readable, as a matter of fact. > + if (__cond) __build_bug_on_failed = 1; \ > } while(0) > #endif Thanks. -- Regards/Gruss, Boris. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/