Powered by Linux
[PATCH] Add -Wexternal-function-has-definition — Semantic Matching Tool

[PATCH] Add -Wexternal-function-has-definition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <john.levon@xxxxxxxxxx>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 cgcc     | 2 +-
 lib.c    | 2 ++
 lib.h    | 1 +
 parse.c  | 4 ++--
 sparse.1 | 7 +++++++
 5 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/cgcc b/cgcc
index 4893df82..43c4b1d2 100755
--- a/cgcc
+++ b/cgcc
@@ -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)?$/;
diff --git a/lib.c b/lib.c
index 2ea890da..569a1533 100644
--- a/lib.c
+++ b/lib.c
@@ -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 },
diff --git a/lib.h b/lib.h
index 8895ddaa..de8f1132 100644
--- a/lib.h
+++ b/lib.h
@@ -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;
diff --git a/parse.c b/parse.c
index 53144757..44f32bbe 100644
--- a/parse.c
+++ b/parse.c
@@ -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))
diff --git a/sparse.1 b/sparse.1
index beb48442..f4585993 100644
--- a/sparse.1
+++ b/sparse.1
@@ -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.
 
-- 
2.17.1




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux