From: Pavel Roskin <proski@gnu.org>
To: linux-sparse@vger.kernel.org
Subject: [RFC PATCH] Fix -Wtypesign
Date: Thu, 13 Jul 2006 21:56:18 -0400 [thread overview]
Message-ID: <1152842178.480.26.camel@dv> (raw)
Hello!
The current sparse has problems with the -Wtypesign flag. If causes
bogus warnings. Take for example following test.c:
static unsigned char foobar(void);
static unsigned char foobar(void)
{
return 0;
}
$ sparse -Wtypesign test.c
test.c:2:22: error: symbol 'foobar' redeclared with different type
(originally declared at test.c:1) - different signedness
Debugging shows that the function definition doesn't have the
signed/unsigned modifiers, unlike the function declaration:
2412 typediff = type_difference(sym, next, 0, 0);
(gdb) p/ sym->ctype.modifiers
$1 = 0x800004
(gdb) p/ next->ctype.modifiers
$2 = 0x800084
0x80 is MOD_UNSIGNED.
The signedness modifiers are set in evaluate_symbol(), which hasn't been
called for sym yet. I have devised following patch, that appears to fix
the problem:
---
Fix -Wtypesign
Run evaluate_symbol() before check_duplicates() so that the signedness
of the token is known by the time the token is compared with other
tokens.
Signed-off-by: Pavel Roskin <proski@gnu.org>
---
evaluate.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/evaluate.c b/evaluate.c
index 42005eb..2561f38 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2473,8 +2473,8 @@ void evaluate_symbol_list(struct symbol_
struct symbol *sym;
FOR_EACH_PTR(list, sym) {
- check_duplicates(sym);
evaluate_symbol(sym);
+ check_duplicates(sym);
} END_FOR_EACH_PTR(sym);
}
I tested -Wtypesign on some Linux drivers. It found some real sign
mismatches and no bogus warnings.
Still, I haven't seen sparse code until today, so the patch should be
evaluated carefully.
--
Regards,
Pavel Roskin
next reply other threads:[~2006-07-14 1:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-14 1:56 Pavel Roskin [this message]
2006-07-14 5:36 ` [RFC PATCH] Fix -Wtypesign Linus Torvalds
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=1152842178.480.26.camel@dv \
--to=proski@gnu.org \
--cc=linux-sparse@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