diff options
author | John Levon <john.levon@joyent.com> | 2019-11-12 16:13:58 +0000 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-12 21:51:31 +0100 |
commit | fd3528aa0409874386610ce63bb647fff8312fd9 (patch) | |
tree | 8f704874f4cbc634a9359f3fbf047f4eb907c9ee | |
parent | cb75739a5e07b0f435b9e2685033e1ba9ebc31cf (diff) | |
download | sparse-fd3528aa0409874386610ce63bb647fff8312fd9.tar.gz |
Add -Wexternal-function-has-definition
Some older codebases hit this warning all the time, so it's useful
to be able to disable it.
Signed-off-by: John Levon <john.levon@joyent.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rwxr-xr-x | cgcc | 2 | ||||
-rw-r--r-- | lib.c | 2 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | parse.c | 4 | ||||
-rw-r--r-- | sparse.1 | 7 |
5 files changed, 13 insertions, 3 deletions
@@ -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)?$/; @@ -269,6 +269,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; @@ -696,6 +697,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 }, @@ -154,6 +154,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; @@ -2769,8 +2769,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)) @@ -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. |