linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Josh Triplett <josh@joshtriplett.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	linux-sparse@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH V3] sparse: Allow override of sizeof(bool) warning
Date: Wed, 26 Feb 2014 19:19:25 -0800	[thread overview]
Message-ID: <1393471165.24588.79.camel@joe-AO722> (raw)
In-Reply-To: <20140227025845.GA25145@thin>

Allow an override to emit or not the sizeof(bool) warning.
Add a "-Wsizeof-bool" description to the manpage.

Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
---
v2: Add manpage
v3: gah.  Joe knows his alphabet (sometimes). (shadow _then_ sizeof)

 evaluate.c | 3 ++-
 lib.c      | 2 ++
 lib.h      | 1 +
 sparse.1   | 9 +++++++++
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/evaluate.c b/evaluate.c
index 6655615..a45f59b 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2057,7 +2057,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr)
 	}
 
 	if (size == 1 && is_bool_type(type)) {
-		warning(expr->pos, "expression using sizeof bool");
+		if (Wsizeof_bool)
+			warning(expr->pos, "expression using sizeof bool");
 		size = bits_in_char;
 	}
 
diff --git a/lib.c b/lib.c
index bf3e91c..d6ac79d 100644
--- a/lib.c
+++ b/lib.c
@@ -226,6 +226,7 @@ int Wparen_string = 0;
 int Wptr_subtraction_blows = 0;
 int Wreturn_void = 0;
 int Wshadow = 0;
+int Wsizeof_bool = 1;
 int Wtransparent_union = 0;
 int Wtypesign = 0;
 int Wundef = 0;
@@ -438,6 +439,7 @@ static const struct warning {
 	{ "ptr-subtraction-blows", &Wptr_subtraction_blows },
 	{ "return-void", &Wreturn_void },
 	{ "shadow", &Wshadow },
+	{ "sizeof-bool", &Wsizeof_bool },
 	{ "transparent-union", &Wtransparent_union },
 	{ "typesign", &Wtypesign },
 	{ "undef", &Wundef },
diff --git a/lib.h b/lib.h
index f09b338..f6cd9b4 100644
--- a/lib.h
+++ b/lib.h
@@ -120,6 +120,7 @@ extern int Wparen_string;
 extern int Wptr_subtraction_blows;
 extern int Wreturn_void;
 extern int Wshadow;
+extern int Wsizeof_bool;
 extern int Wtransparent_union;
 extern int Wtypesign;
 extern int Wundef;
diff --git a/sparse.1 b/sparse.1
index cd6be26..b7a5b5c 100644
--- a/sparse.1
+++ b/sparse.1
@@ -297,6 +297,15 @@ Such declarations can lead to error-prone code.
 Sparse does not issue these warnings by default.
 .
 .TP
+.B \-Wsizeof-bool
+Warn when checking the sizeof a _Bool.
+
+C99 does not specify the sizeof a _Bool.  gcc uses 1.
+
+Sparse issues these warnings by default.  To turn them off, use
+\fB\-Wno\-sizeof\-bool\fR.
+.
+.TP
 .B \-Wtransparent\-union
 Warn about any declaration using the GCC extension
 \fB__attribute__((transparent_union))\fR.
-- 
1.8.1.2.459.gbcd45b4.dirty




  reply	other threads:[~2014-02-27  3:19 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <530E6F76.1070605@zytor.com>
     [not found] ` <1393462087.24588.50.camel@joe-AO722>
     [not found]   ` <530E8C2E.7080307@zytor.com>
2014-02-27  2:03     ` [PATCH] sparse: Allow override of sizeof(bool) warning Joe Perches
2014-02-27  2:28       ` Josh Triplett
2014-02-27  2:53         ` [PATCH V2] " Joe Perches
2014-02-27  2:58           ` Josh Triplett
2014-02-27  3:19             ` Joe Perches [this message]
2014-02-27  3:29             ` H. Peter Anvin
2014-02-27  3:38               ` Joe Perches
2014-02-27  3:42                 ` H. Peter Anvin
2014-02-27  8:25                   ` Borislav Petkov
2014-02-27 15:10                     ` H. Peter Anvin
2014-02-27 15:24                       ` Theodore Ts'o
2014-02-27 15:48                         ` H. Peter Anvin
2014-02-27 16:01                           ` Borislav Petkov
2014-02-27 16:10                           ` Dan Carpenter
2014-02-27 16:52                             ` H. Peter Anvin
2014-02-27 17:06                               ` James Hogan
2014-02-27  4:00                 ` Ben Pfaff
2014-02-27  4:19                   ` H. Peter Anvin
2014-02-27  4:26                     ` Ben Pfaff
2014-02-27  4:32                       ` H. Peter Anvin
2014-02-27 20:22                         ` Christopher Li
2014-02-27 20:26                           ` H. Peter Anvin
2014-02-27 20:39                             ` Joe Perches
2014-02-27 20:55                               ` Christopher Li
2014-02-27 21:49                                 ` Joe Perches
2014-02-27 20:44                             ` Christopher Li
2014-02-27 21:00                               ` Joe Perches
2014-02-27 21:03                                 ` Christopher Li
2014-02-27 21:41                                 ` Christopher Li

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=1393471165.24588.79.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=hpa@zytor.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).