From: "Alexey Zaytsev" <alexey.zaytsev@gmail.com>
To: Josh Triplett <josht@linux.vnet.ibm.com>
Cc: David Given <dg@cowlark.com>, linux-sparse@vger.kernel.org
Subject: Re: Odd sparse behaviour
Date: Mon, 7 Jul 2008 22:09:56 +0400 [thread overview]
Message-ID: <f19298770807071109s529f2215sc4b7d7f1f7011208@mail.gmail.com> (raw)
In-Reply-To: <1215452912.3003.27.camel@josh-work.beaverton.ibm.com>
On Mon, Jul 7, 2008 at 9:48 PM, Josh Triplett <josht@linux.vnet.ibm.com> wrote:
> On Sun, 2008-07-06 at 22:33 +0100, David Given wrote:
>> I've found a couple of places where sparse behaves rather oddly.
>>
>> Firstly, if you declare something static, and then try to define it
>> later, sparse appears to get confused:
>>
>> ---snip---
>> static int i;
>> int i = 0;
>> ---snip---
>>
>> $ ./test-parsing test.c
>> test.c:2:5: warning: symbol 'i' was not declared. Should it be static?
>>
>> .align 4
>> int static [signed] [toplevel] i,
>> .align 4
>> int [signed] [addressable] [toplevel] i =
>> movi.32 v1,$0
>>
>> Enumeration of the list of defined symbols shows two different symbols
>> with the name 'i'. This isn't entirely obvious when using the test tools
>> as, of course, two strings with the same value look the same! This is
>> causing me issues with forward declarations of static functions:
>>
>> static void foo();
>> { ... foo(); ... } // calls static foo
>>
>> foo() {} // defines extern foo
>> { ... foo(); ... } // calls extern foo
>>
>> This then leads to link errors as static foo hasn't been found.
>
> I've observed this problem before. Alexey Zaytsev reported this as
> well. I think he may have a fix in the works. Alexey?
I did some research, but no working patch so far. If you'd like to
look at it yourself, I'd suggest lookign at parse.c:external_declaration().
Right now it reads:
/* Parse declaration-specifiers, if any */
token = declaration_specifiers(token, &ctype, 0);
decl = alloc_symbol(token->pos, SYM_NODE);
decl->ctype = ctype;
token = declarator(token, decl, &ident);
apply_modifiers(token->pos, &decl->ctype);
I think that after calling declaration_specifiers(), we should
check if token_type(token) == TOKEN_IDENT and lookup
the symbol in the relevant namespaces. If it is found, we shoud
check if the types and produce soe warnings. And reuse the
symbol, if the types match.
Josh, does this make any sense?
>
>> The second issue is with the following piece of C99 code:
>>
>> ---snip---
>> extern void nop(void)
>> void bar(void)
>> { for (int i=0; i<10; i++) nop(); }
>> ---snip---
>>
>> $ ./test-linearise test.c
>> test.c:3:6: warning: symbol 'bar' was not declared. Should it be static?
>> bar:
>> .L0xb7d7600c:
>> <entry-point>
>> br .L0xb7d76038
>>
>> .L0xb7d76038:
>> call nop
>> br .L0xb7d76038
>>
>> The for loop seems to silently turn into an infinite loop. Which did
>> cause one of my benchmarks to, um, produce rather poor results...
>
> No kidding. An interesting bug. Does this go away if you declare "int
> i" at the top of the function?
>
>> (You may be interested to know that my compiler is now producing
>> working, running code for non-trivial apps. Big chunks of it do need
>> throwing away and rewriting, but it's actually *working*!)
>
> Awesome!
>
> - Josh Triplett
>
>
>
next prev parent reply other threads:[~2008-07-07 18:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-06 21:33 Odd sparse behaviour David Given
2008-07-07 17:48 ` Josh Triplett
2008-07-07 18:09 ` Alexey Zaytsev [this message]
2008-07-07 19:42 ` Christopher Li
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=f19298770807071109s529f2215sc4b7d7f1f7011208@mail.gmail.com \
--to=alexey.zaytsev@gmail.com \
--cc=dg@cowlark.com \
--cc=josht@linux.vnet.ibm.com \
--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;
as well as URLs for NNTP newsgroup(s).