From: John Levon <levon@movementarian.org>
Subject: [PATCH 06/18] sparse: add -Wno-non-ansi-function-declaration
Date: Thu, 22 Nov 2018 13:05:15 +0000 [thread overview]
Message-ID: <E1gQCRW-00067o-Ra@movementarian.org> (raw)
Signed-off-by: John Levon <levon@movementarian.org>
---
cgcc | 2 +-
lib.c | 2 ++
lib.h | 1 +
parse.c | 11 +++++++----
sparse.1 | 7 +++++++
validation/non-ansi-function-declaration.c | 10 ++++++++++
6 files changed, 28 insertions(+), 5 deletions(-)
create mode 100644 validation/non-ansi-function-declaration.c
diff --git a/cgcc b/cgcc
index 9f61595d..b85d508b 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-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|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/lib.c b/lib.c
index d7cd8cbc..e6a3bc4b 100644
--- a/lib.c
+++ b/lib.c
@@ -237,6 +237,7 @@ int Winit_cstring = 0;
int Wenum_mismatch = 1;
int Wsparse_error = 0;
int Wmemcpy_max_count = 1;
+int Wnon_ansi_function_declaration = 1;
int Wnon_pointer_null = 1;
int Wold_initializer = 1;
int Wone_bit_signed_bitfield = 1;
@@ -539,6 +540,7 @@ static const struct warning {
{ "enum-mismatch", &Wenum_mismatch },
{ "init-cstring", &Winit_cstring },
{ "memcpy-max-count", &Wmemcpy_max_count },
+ { "non-ansi-function-declaration", &Wnon_ansi_function_declaration },
{ "non-pointer-null", &Wnon_pointer_null },
{ "old-initializer", &Wold_initializer },
{ "one-bit-signed-bitfield", &Wone_bit_signed_bitfield },
diff --git a/lib.h b/lib.h
index 6a86d1bc..05579cce 100644
--- a/lib.h
+++ b/lib.h
@@ -128,6 +128,7 @@ extern int Wenum_mismatch;
extern int Wsparse_error;
extern int Winit_cstring;
extern int Wmemcpy_max_count;
+extern int Wnon_ansi_function_declaration;
extern int Wnon_pointer_null;
extern int Wold_initializer;
extern int Wone_bit_signed_bitfield;
diff --git a/parse.c b/parse.c
index 66a27692..ab8f4f75 100644
--- a/parse.c
+++ b/parse.c
@@ -1698,9 +1698,10 @@ static enum kind which_func(struct token *token,
/* don't complain about those */
if (!n || match_op(next->next, ';'))
return Empty;
- warning(next->pos,
- "non-ANSI function declaration of function '%s'",
- show_ident(*n));
+ if (Wnon_ansi_function_declaration)
+ warning(next->pos,
+ "non-ANSI function declaration of function '%s'",
+ show_ident(*n));
return Empty;
}
@@ -2783,7 +2784,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 (Wnon_ansi_function_declaration)
+ 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/sparse.1 b/sparse.1
index 3bd5f1cb..63bd923e 100644
--- a/sparse.1
+++ b/sparse.1
@@ -230,6 +230,13 @@ The limit can be changed with \fB\-fmemcpy\-max\-count=COUNT\fR,
the default being \fB100000\fR.
.
.TP
+.B \-Wnon\-ansi\-function\-declaration
+Warn about non-ANSI function declarations.
+
+Sparse issues these warnings by default. To turn them off, use
+\fB\-Wno\-non\-ansi\-function\-declaration\fR.
+.
+.TP
.B \-Wnon\-pointer\-null
Warn about the use of 0 as a NULL pointer.
diff --git a/validation/non-ansi-function-declaration.c b/validation/non-ansi-function-declaration.c
new file mode 100644
index 00000000..48a72948
--- /dev/null
+++ b/validation/non-ansi-function-declaration.c
@@ -0,0 +1,10 @@
+
+
+extern void myfunction(), myfunc2();
+
+/*
+ * check-name: -Wno-non-ansi-function-declaration works
+ * check-command: sparse -Wno-non-ansi-function-declaration $file
+ * check-error-start
+ * check-error-end
+ */
--
2.14.1
reply other threads:[~2018-11-24 1:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=E1gQCRW-00067o-Ra@movementarian.org \
--to=levon@movementarian.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 read-only IMAP folder(s) and NNTP newsgroup(s).