From: John Levon <john.levon@joyent.com>
To: smatch@vger.kernel.org
Cc: John Levon <john.levon@joyent.com>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH] Add -Wexternal-function-has-definition
Date: Wed, 13 Nov 2019 16:51:18 +0000 [thread overview]
Message-ID: <1573663878-9921-1-git-send-email-john.levon@joyent.com> (raw)
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@joyent.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
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
reply other threads:[~2019-11-13 16:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1573663878-9921-1-git-send-email-john.levon@joyent.com \
--to=john.levon@joyent.com \
--cc=luc.vanoostenryck@gmail.com \
--cc=smatch@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).