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 9f61595..b85d508 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 0f7ad2a..8728759 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; @@ -534,6 +535,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 6a86d1b..05579cc 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 66a2769..ab8f4f7 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 3bd5f1c..63bd923 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 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