From: Daniel Santos <danielfsantos@att.net>
To: Paul Gortmaker <paul.gortmaker@windriver.com>,
Jason Wessel <jason.wessel@windriver.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] linux/bug.h: make BUILD_BUG_ON generate compile-time error
Date: Mon, 04 Jun 2012 06:35:27 -0500 [thread overview]
Message-ID: <4FCC9D7F.7070404@att.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 637 bytes --]
This is pretty straight-forward. __compiletime_error is defined in
compiler-gcc4.h with appropriate version checks, so shouldn't break on
older compilers. This makes the difference between getting an error at
link-time and getting one at compile time. Example:
/home/daniel/proj/kernel/grbtest/grbtest2.c:83:2: error: call to
‘__build_bug_on_failed’ declared with attribute error: BUILD_BUG_ON
failed: !__builtin_constant_p(count)
The above points me directly to where I called BUILD_BUG_ON. Note that
I'm moving __build_bug_on_failed out of the global scope, just so it can
be re-declared with different attributes each time.
Daniel
[-- Attachment #2: 0006-linux-bug.h-make-BUILD_BUG_ON-generate-compile-time-.patch --]
[-- Type: text/x-patch, Size: 1076 bytes --]
>From 3af9a38225e6d074ef6b22e6c99c2503bc581953 Mon Sep 17 00:00:00 2001
From: Daniel Santos <daniel.santos@pobox.com>
Date: Mon, 4 Jun 2012 06:13:41 -0500
Subject: linux/bug.h: make BUILD_BUG_ON generate compile-time error
---
include/linux/bug.h | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/linux/bug.h b/include/linux/bug.h
index 72961c3..d35d6e9 100644
--- a/include/linux/bug.h
+++ b/include/linux/bug.h
@@ -48,11 +48,12 @@ struct pt_regs;
#ifndef __OPTIMIZE__
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
#else
-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; \
+#define BUILD_BUG_ON(condition) \
+ do { \
+ extern void __build_bug_on_failed(void) \
+ __compiletime_error("BUILD_BUG_ON failed: " #condition);\
+ ((void)sizeof(char[1 - 2*!!(condition)])); \
+ if (condition) __build_bug_on_failed(); \
} while(0)
#endif
--
1.7.3.4
next reply other threads:[~2012-06-04 11:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-04 11:35 Daniel Santos [this message]
2012-06-04 14:32 ` [PATCH] linux/bug.h: make BUILD_BUG_ON generate compile-time error Paul Gortmaker
2012-06-04 20:04 ` Daniel Santos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FCC9D7F.7070404@att.net \
--to=danielfsantos@att.net \
--cc=daniel.santos@pobox.com \
--cc=jason.wessel@windriver.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paul.gortmaker@windriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.