From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steven Rostedt Subject: Re: [PATCH v2 09/10] bug.h: Add BUILD_BUG_ON_MSG & BUILD_BUG_INTERNAL{,2} Date: Fri, 05 Oct 2012 17:04:08 -0400 Message-ID: <1349471048.6755.77.camel@gandalf.local.home> References: <1349465759-20524-1-git-send-email-daniel.santos@pobox.com> <1349466169-20637-9-git-send-email-daniel.santos@pobox.com> <20121005205858.GB28452@liondog.tnic> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from hrndva-omtalb.mail.rr.com ([71.74.56.122]:12885 "EHLO hrndva-omtalb.mail.rr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932275Ab2JEVEL (ORCPT ); Fri, 5 Oct 2012 17:04:11 -0400 In-Reply-To: <20121005205858.GB28452@liondog.tnic> Sender: linux-sparse-owner@vger.kernel.org List-Id: linux-sparse@vger.kernel.org To: Borislav Petkov Cc: danielfsantos@att.net, LKML , Andi Kleen , Andrea Arcangeli , Andrew Morton , Christopher Li , David Daney , David Howells , David Rientjes , Joe Perches , Konstantin Khlebnikov , linux-sparse@vger.kernel.org, Michel Lespinasse , Paul Gortmaker , Pavel Pisa , Peter Zijlstra , Daniel Santos On Fri, 2012-10-05 at 22:58 +0200, Borislav Petkov wrote: > On Fri, Oct 05, 2012 at 02:42:48PM -0500, danielfsantos@att.net wrote= : > > Add BUILD_BUG_ON_MSG which behaves like BUILD_BUG_ON (with optimiza= tions > > turned enabled), except that it allows you to specify the error mes= sage > > you want emitted as the third parameter. Under the hood, this reli= es on > > BUILD_BUG_INTERNAL{,2}, which does the actual work and is pretty-mu= ch > > identical to BUILD_BUG_ON. > >=20 > > Signed-off-by: Daniel Santos > > --- > > include/linux/bug.h | 26 ++++++++++++++++++++++++++ > > 1 files changed, 26 insertions(+), 0 deletions(-) > >=20 > > diff --git a/include/linux/bug.h b/include/linux/bug.h > > index 1b43ea2..91bd9d5 100644 > > --- a/include/linux/bug.h > > +++ b/include/linux/bug.h > > @@ -16,6 +16,7 @@ struct pt_regs; > > #define BUILD_BUG_ON_NOT_POWER_OF_2(n) > > #define BUILD_BUG_ON_ZERO(e) (0) > > #define BUILD_BUG_ON_NULL(e) ((void*)0) > > +#define BUILD_BUG_ON_MSG(cond, msg) (0) > > #define BUILD_BUG_ON(condition) (0) > > #define BUILD_BUG() (0) > > #else /* __CHECKER__ */ > > @@ -38,6 +39,31 @@ struct pt_regs; > > */ > > #define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e)))= ) > > =20 > > +#define _CONCAT1(a, b) a##b > > +#define CONCAT(a, b) _CONCAT1(a, b) >=20 > Let's call the indirection _CONCAT without the "1". You're stricter than I ;-) >=20 > > +#define UNIQUIFY(prefix) CONCAT(prefix, __LINE__) > > + > > +#define BUILD_BUG_INTERNAL2(condition, msg, fn) \ > > + do { \ > > + extern void fn (void) __compiletime_error(msg); \ > > + __compiletime_error_fallback(condition); \ > > + if (condition) \ > > + fn(); \ > > + } while (0) > > + > > +#define BUILD_BUG_INTERNAL(condition, msg, fn) \ > > + BUILD_BUG_INTERNAL2(condition, msg, fn) >=20 > Ditto. BUILD_BUG_INTERNAL2 should be __BUILD_BUG_INTERNAL and the one > calling it _BUILD_BUG_INTERNAL (with one underscore). I thought about commenting about the '2' too, but figured it's only use= d internally by BUILD_BUG_INTERNAL and was really not too concerned about such a trivial thing. It could have been 42 for all I care ;-) >=20 > > + > > +/** > > + * BUILD_BUG_ON_MSG - break compile if a condition is true & emit = supplied > > + * error message. > > + * @condition: the condition which the compiler should know is fal= se. > > + * > > + * See BUILD_BUG_ON for description. > > + */ > > +#define BUILD_BUG_ON_MSG(cond, msg) \ > > + BUILD_BUG_INTERNAL(cond, msg, UNIQUIFY(__build_bug_on_failed_)) >=20 > Btw, why are we adding the line at all? It is issued by gcc anyway: >=20 > cc -Wall macros.c -o macros > macros.c: In function =E2=80=98main=E2=80=99: > macros.c:22:1: error: =E2=80=98__build_bug_on_failed_22=E2=80=99 unde= clared (first use in this function) > ^^^^ >=20 > It is in front of the filename here. >=20 > macros.c:22:1: note: each undeclared identifier is reported only once= for each function it appears in > make: *** [macros] Error 1 I was thinking that the number was added as a safety measure that the line number would be shown for all versions of the compiler. I'm not sure it is. -- Steve -- To unsubscribe from this list: send the line "unsubscribe linux-sparse"= in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html