Add -Wexternal-function-has-definition
PATCH 1/1 Add -Wexternal-function-has-definition
Some older codebases hit this warning all the time, so it's useful to be able to disable it.
(Ported from sparse upstream.)
Signed-off-by John Levon <[email protected]>
Signed-off-by Luc Van Oostenryck <[email protected]>
--- cgcc | 2 +- lib.c | 2 ++ lib.h | 1 + parse.c | 4 ++-- sparse.1 | 7 +++++++ 5 files changed, 13 insertions(+), 3 deletions(-)
cgcc +1 -1
@@ -127,7 +127,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|external-function-has-definition|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 =~ /^-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)?$/;
lib.c +2 -0
@@ -272,6 +272,7 @@ int Wimplicit_int = 1;int Winit_cstring =0 ;int Wint_to_pointer_cast =1 ;int Wenum_mismatch =1 ; +int Wexternal_function_has_definition =1 ;int Wsparse_error =0 ;int Wmemcpy_max_count =1 ;int Wnon_pointer_null =1 ;
@@ -651,6 +652,7 @@ static const struct flag warnings[] = { { "designated-init", &Wdesignated_init }, { "do-while", &Wdo_while }, { "enum-mismatch", &Wenum_mismatch }, + { "external-function-has-definition", &Wexternal_function_has_definition }, { "implicit-int", &Wimplicit_int }, { "init-cstring", &Winit_cstring }, { "int-to-pointer-cast", &Wint_to_pointer_cast },
lib.h +1 -0
@@ -153,6 +153,7 @@ extern int Wdefault_bitfield_sign;extern int Wdesignated_init;extern int Wdo_while;extern int Wenum_mismatch; +extern int Wexternal_function_has_definition;extern int Wsparse_error;extern int Wimplicit_int;extern int Winit_cstring;
parse.c +2 -2
@@ -2819,8 +2819,8 @@ static struct token *parse_function_body(struct token *token, struct symbol *dec function_computed_target_list =NULL ; function_computed_goto_list =NULL ; -if (decl->ctype.modifiers &MOD_EXTERN ) { -if (!(decl->ctype.modifiers &MOD_INLINE )) +if ((decl->ctype.modifiers & (MOD_EXTERN |MOD_INLINE )) ==MOD_EXTERN ) { +if (Wexternal_function_has_definition)warning (decl->pos,"function '%s' with external linkage has definition" ,show_ident (decl->ident)); }if (!(decl->ctype.modifiers &MOD_STATIC ))
sparse.1 +7 -0
@@ -244,6 +244,13 @@ Sparse issues these warnings by default. To turn them off, use \fB\-Wno\-enum\-mismatch\fR. . .TP +.B \-Wexternal\-function\-has\-definition +Warn about function definitions that are declared with external linkage. + +Sparse issues these warnings by default. To turn them off, use +\fB\-Wno\-external\-function\-has\-definition\fR. +. +.TP .B \-Winit\-cstring Warn about initialization of a char array with a too long constant C string.
Signature · 1 line
2.17.1