* BUG: sparse redeclaration warning when assigning to a declared variable!
@ 2007-03-08 17:53 Blaisorblade
2007-03-08 18:06 ` Linus Torvalds
0 siblings, 1 reply; 2+ messages in thread
From: Blaisorblade @ 2007-03-08 17:53 UTC (permalink / raw)
To: Sparse ML
What I saw running sparse on Linux source tree:
paolo [linux-2.6.20] $ make C=2 mm/page-writeback.o
CHK include/linux/version.h
CHK include/linux/utsrelease.h
CHECK scripts/mod/empty.c
CHECK mm/page-writeback.c
mm/page-writeback.c:912:9: warning: symbol 'ret' shadows an earlier one
mm/page-writeback.c:906:6: originally declared here
mm/page-writeback.c:919:9: warning: symbol 'ret' shadows an earlier one
mm/page-writeback.c:906:6: originally declared here
mm/page-writeback.c:933:9: warning: symbol 'ret' shadows an earlier one
mm/page-writeback.c:927:6: originally declared here
mm/page-writeback.c:944:9: warning: symbol 'ret' shadows an earlier one
mm/page-writeback.c:927:6: originally declared here
CC mm/page-writeback.o
Code giving one of these warnings (kernel tree 2.6.20.1), other warnings are
like this. I.e.:
ret = something()
is seen as redeclaration.
int test_set_page_writeback(struct page *page)
{
struct address_space *mapping = page_mapping(page);
int ret;
if (mapping) {
unsigned long flags;
write_lock_irqsave(&mapping->tree_lock, flags);
ret = TestSetPageWriteback(page);
if (!ret)
radix_tree_tag_set(&mapping->page_tree,
page_index(page),
PAGECACHE_TAG_WRITEBACK);
if (!PageDirty(page))
radix_tree_tag_clear(&mapping->page_tree,
page_index(page),
PAGECACHE_TAG_DIRTY);
write_unlock_irqrestore(&mapping->tree_lock, flags);
} else {
ret = TestSetPageWriteback(page);
}
return ret;
}
Tested with both sparse v0.2 and my git HEAD, where I get:
sparse.git $ git-describe
0.2-41-g309f380
Bye
--
Inform me of my mistakes, so I can add them to my list!
Paolo Giarrusso, aka Blaisorblade
http://www.user-mode-linux.org/~blaisorblade
Chiacchiera con i tuoi amici in tempo reale!
http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: BUG: sparse redeclaration warning when assigning to a declared variable!
2007-03-08 17:53 BUG: sparse redeclaration warning when assigning to a declared variable! Blaisorblade
@ 2007-03-08 18:06 ` Linus Torvalds
0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2007-03-08 18:06 UTC (permalink / raw)
To: Blaisorblade; +Cc: Sparse ML
On Thu, 8 Mar 2007, Blaisorblade wrote:
>
> Code giving one of these warnings (kernel tree 2.6.20.1), other warnings are
> like this. I.e.:
> ret = something()
> is seen as redeclaration.
No. Sparse is actually correct, but you didn't notice that there is
*another* "ret" there.
See how TestClearPageWriteback() is declared in <linux/page-flags.h>. THAT
is the "ret" that shadows an earlier one..
(And no, a macro should not use a common name like that - imagine if you
call it with an argument that really is "struct page *ret", and thing what
happens to the TestClearPageWritepage expansion..)
So sparse in this case does seem to be pointing out a potentially
dangerous situation, where a macro declares a local variable with the same
name as a user of that macro.
Linus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-03-08 18:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-08 17:53 BUG: sparse redeclaration warning when assigning to a declared variable! Blaisorblade
2007-03-08 18:06 ` Linus Torvalds
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 NNTP newsgroup(s).