[PATCH 03/12] sparse: add -Wbig-constants

John Levon <[email protected]>
Newsgroups org.kernel.vger.smatch
Message-ID <[email protected]>
Signed-off-by: John Levon <[email protected]>
---
 cgcc         | 2 +-
 expression.c | 3 +++
 lib.c        | 2 ++
 lib.h        | 1 +
 sparse.1     | 7 +++++++
 5 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/cgcc b/cgcc
index b85d508..04869c1 100755
--- a/cgcc
+++ b/cgcc
@@ -101,7 +101,7 @@ exit 0;
 
 sub check_only_option {
     my ($arg) = @_;
-    return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|init-cstring|memcpy-max-count|non-ansi-function-declaration|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
+    return 1 if $arg =~ /^-W(no-?)?(address-space|big-constants|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|init-cstring|memcpy-max-count|non-ansi-function-declaration|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
     return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/;
     return 1 if $arg =~ /^-f(dump-linearize|memcpy-max-count)(=\S*)?$/;
     return 0;
diff --git a/expression.c b/expression.c
index 9907e32..097c0a7 100644
--- a/expression.c
+++ b/expression.c
@@ -318,6 +318,9 @@ static void get_number_value(struct expression *expr, struct token *token)
 			show_token(token));
 	want_unsigned = 1;
 got_it:
+	if (!Wbig_constants)
+		do_warn = 0;
+
 	if (do_warn)
 		warning(expr->pos, "constant %s is so big it is%s%s%s",
 			show_token(token),
diff --git a/lib.c b/lib.c
index 8728759..ed7d9ed 100644
--- a/lib.c
+++ b/lib.c
@@ -223,6 +223,7 @@ static struct token *pre_buffer_end = NULL;
 
 int Waddress = 0;
 int Waddress_space = 1;
+int Wbig_constants = 1;
 int Wbitwise = 1;
 int Wcast_to_as = 0;
 int Wcast_truncate = 1;
@@ -522,6 +523,7 @@ static const struct warning {
 } warnings[] = {
 	{ "address", &Waddress },
 	{ "address-space", &Waddress_space },
+	{ "big-constants", &Wbig_constants },
 	{ "bitwise", &Wbitwise },
 	{ "cast-to-as", &Wcast_to_as },
 	{ "cast-truncate", &Wcast_truncate },
diff --git a/lib.h b/lib.h
index 05579cc..bfb3546 100644
--- a/lib.h
+++ b/lib.h
@@ -114,6 +114,7 @@ extern int preprocess_only;
 
 extern int Waddress;
 extern int Waddress_space;
+extern int Wbig_constants;
 extern int Wbitwise;
 extern int Wcast_to_as;
 extern int Wcast_truncate;
diff --git a/sparse.1 b/sparse.1
index 63bd923..cc72ad6 100644
--- a/sparse.1
+++ b/sparse.1
@@ -42,6 +42,13 @@ Sparse issues these warnings by default.  To turn them off, use
 \fB\-Wno\-address\-space\fR.
 .
 .TP
+.B \-Wbig-constants
+Warn about large integer constants that are not qualified by a size suffix.
+
+Sparse issues these warnings by default.  To turn them off, use
+\fB\-Wno\-big\-constants\fR.
+.
+.TP
 .B \-Wbitwise
 Warn about unsupported operations or type mismatches with restricted integer
 types.
-- 
1.8.3.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.