Skip to contentSkip to conversation

BUG: sparse redeclaration warning when assigning to a declared variable!

DISCUSSION Blaisorblade 2 participants 2 messages Mar 8, 2007 Sparse checker

lore
Share & tools
lore
#0 lore raw

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

Signature · 5 lines
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 
#1 lore raw
Quoted 5 lines · Blaisorblade

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