Some environments have large amounts of legacy headers that are pre-ANSI, and can't easily be changed. Default to complaining still, but allow the user to turn this warning off. Signed-off-by: John Levon <levon@xxxxxxxxxxxxxxxxx> --- 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 736cb70..5544a77 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|constant-suffix|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|constant-suffix|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-ir|memcpy-max-count|diagnostic-prefix)(=\S*)?$/; return 1 if $arg =~ /^-f(mem2reg|optim)(-enable|-disable|=last)?$/; diff --git a/lib.c b/lib.c index 5c2059f..a1adcd4 100644 --- a/lib.c +++ b/lib.c @@ -264,6 +264,7 @@ int Wint_to_pointer_cast = 1; 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; @@ -699,6 +700,7 @@ static const struct flag warnings[] = { { "init-cstring", &Winit_cstring }, { "int-to-pointer-cast", &Wint_to_pointer_cast }, { "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 cde74e9..bb47250 100644 --- a/lib.h +++ b/lib.h @@ -154,6 +154,7 @@ extern int Wsparse_error; extern int Winit_cstring; extern int Wint_to_pointer_cast; 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 d4886c4..5445954 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, ';')) 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; } @@ -2792,7 +2793,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 6432322..04ba6a0 100644 --- a/sparse.1 +++ b/sparse.1 @@ -257,6 +257,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 0000000..48a7294 --- /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 + */ -- 1.8.3.1