summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJohn Levon <levon@movementarian.org>2018-11-29 10:42:51 +0000
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-12-01 02:16:24 +0100
commit648380c13ecaaa95c9dfbd500039cd9007ec3c20 (patch)
tree3e6d634f8549a13d97bdbe0fba39aed97364eb9c
parenta0f34e0fd2a44016ef668e19187a342c5f4edf45 (diff)
downloadsparse-648380c13ecaaa95c9dfbd500039cd9007ec3c20.tar.gz
Conditionalize 'warning: non-ANSI function ...'
Sparse unconditionally issues warnings about non-ANSI function declarations & definitions. However, some environments have large amounts of legacy headers that are pre-ANSI, and can't easily be changed. These generate a lot of useless warnings. Fix this by using the options flags -Wstrict-prototypes & -Wold-style-definition to conditionalize these warnings. Signed-off-by: John Levon <levon@movementarian.org> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--lib.c4
-rw-r--r--lib.h2
-rw-r--r--parse.c11
-rw-r--r--validation/old-style-definition0.c14
-rw-r--r--validation/old-style-definition1.c18
-rw-r--r--validation/strict-prototypes0.c7
-rw-r--r--validation/strict-prototypes1.c14
7 files changed, 66 insertions, 4 deletions
diff --git a/lib.c b/lib.c
index 314b65e9..ada12ca7 100644
--- a/lib.c
+++ b/lib.c
@@ -270,6 +270,7 @@ int Wsparse_error = 0;
int Wmemcpy_max_count = 1;
int Wnon_pointer_null = 1;
int Wold_initializer = 1;
+int Wold_style_definition = 1;
int Wone_bit_signed_bitfield = 1;
int Woverride_init = 1;
int Woverride_init_all = 0;
@@ -283,6 +284,7 @@ int Wshadow = 0;
int Wshift_count_negative = 1;
int Wshift_count_overflow = 1;
int Wsizeof_bool = 0;
+int Wstrict_prototypes = 1;
int Wtautological_compare = 0;
int Wtransparent_union = 0;
int Wtypesign = 0;
@@ -707,6 +709,7 @@ static const struct flag warnings[] = {
{ "memcpy-max-count", &Wmemcpy_max_count },
{ "non-pointer-null", &Wnon_pointer_null },
{ "old-initializer", &Wold_initializer },
+ { "old-style-definition", &Wold_style_definition },
{ "one-bit-signed-bitfield", &Wone_bit_signed_bitfield },
{ "override-init", &Woverride_init },
{ "override-init-all", &Woverride_init_all },
@@ -718,6 +721,7 @@ static const struct flag warnings[] = {
{ "shift-count-negative", &Wshift_count_negative },
{ "shift-count-overflow", &Wshift_count_overflow },
{ "sizeof-bool", &Wsizeof_bool },
+ { "strict-prototypes", &Wstrict_prototypes },
{ "pointer-arith", &Wpointer_arith },
{ "sparse-error", &Wsparse_error },
{ "tautological-compare", &Wtautological_compare },
diff --git a/lib.h b/lib.h
index bd578be5..ef80826c 100644
--- a/lib.h
+++ b/lib.h
@@ -158,6 +158,7 @@ extern int Wint_to_pointer_cast;
extern int Wmemcpy_max_count;
extern int Wnon_pointer_null;
extern int Wold_initializer;
+extern int Wold_style_definition;
extern int Wone_bit_signed_bitfield;
extern int Woverride_init;
extern int Woverride_init_all;
@@ -171,6 +172,7 @@ extern int Wshadow;
extern int Wshift_count_negative;
extern int Wshift_count_overflow;
extern int Wsizeof_bool;
+extern int Wstrict_prototypes;
extern int Wtautological_compare;
extern int Wtransparent_union;
extern int Wtypesign;
diff --git a/parse.c b/parse.c
index eaa3ac2e..da912aca 100644
--- a/parse.c
+++ b/parse.c
@@ -1752,9 +1752,10 @@ static enum kind which_func(struct token *token,
/* don't complain about those */
if (!n || match_op(next->next, ';') || match_op(next->next, ','))
return Empty;
- warning(next->pos,
- "non-ANSI function declaration of function '%s'",
- show_ident(*n));
+ if (Wstrict_prototypes)
+ warning(next->pos,
+ "non-ANSI function declaration of function '%s'",
+ show_ident(*n));
return Empty;
}
@@ -2797,7 +2798,9 @@ static struct token *parse_k_r_arguments(struct token *token, struct symbol *dec
{
struct symbol_list *args = NULL;
- warning(token->pos, "non-ANSI definition of function '%s'", show_ident(decl->ident));
+ if (Wold_style_definition)
+ warning(token->pos, "non-ANSI definition of function '%s'", show_ident(decl->ident));
+
do {
token = declaration_list(token, &args);
if (!match_op(token, ';')) {
diff --git a/validation/old-style-definition0.c b/validation/old-style-definition0.c
new file mode 100644
index 00000000..eb522aa6
--- /dev/null
+++ b/validation/old-style-definition0.c
@@ -0,0 +1,14 @@
+extern int foo(int a, void *b);
+
+int foo(a, b)
+ int a;
+ void *b;
+{
+ if (b)
+ return a;
+}
+
+/*
+ * check-name: old-stype-definition disabled
+ * check-command: sparse -Wno-old-style-definition $file
+ */
diff --git a/validation/old-style-definition1.c b/validation/old-style-definition1.c
new file mode 100644
index 00000000..f65d7dfe
--- /dev/null
+++ b/validation/old-style-definition1.c
@@ -0,0 +1,18 @@
+extern int foo(int a, void *b);
+
+int foo(a, b)
+ int a;
+ void *b;
+{
+ if (b)
+ return a;
+}
+
+/*
+ * check-name: old-stype-definition enabled
+ * check-command: sparse -Wold-style-definition $file
+ *
+ * check-error-start
+old-style-definition1.c:4:9: warning: non-ANSI definition of function 'foo'
+ * check-error-end
+ */
diff --git a/validation/strict-prototypes0.c b/validation/strict-prototypes0.c
new file mode 100644
index 00000000..e320846b
--- /dev/null
+++ b/validation/strict-prototypes0.c
@@ -0,0 +1,7 @@
+extern void func1();
+extern void myfunction(), myfunc2();
+
+/*
+ * check-name: strict-prototypes disabled
+ * check-command: sparse -Wno-strict-prototypes $file
+ */
diff --git a/validation/strict-prototypes1.c b/validation/strict-prototypes1.c
new file mode 100644
index 00000000..7e4ce6bb
--- /dev/null
+++ b/validation/strict-prototypes1.c
@@ -0,0 +1,14 @@
+extern void func0();
+extern void func1(), func2();
+
+/*
+ * check-name: strict-prototypes enabled
+ * check-command: sparse -Wstrict-prototypes $file
+ * check-known-to-fail
+ *
+ * check-error-start
+strict-prototypes1.c:1:18: warning: non-ANSI function declaration of function 'func0'
+strict-prototypes1.c:2:18: warning: non-ANSI function declaration of function 'func1'
+strict-prototypes1.c:2:27: warning: non-ANSI function declaration of function 'func2'
+ * check-error-end
+ */