linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Odd sparse behaviour
@ 2008-07-06 21:33 David Given
  2008-07-07 17:48 ` Josh Triplett
  0 siblings, 1 reply; 4+ messages in thread
From: David Given @ 2008-07-06 21:33 UTC (permalink / raw)
  To: linux-sparse

[-- Attachment #1: Type: text/plain, Size: 1995 bytes --]

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.


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...

(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*!)

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-07 19:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-06 21:33 Odd sparse behaviour David Given
2008-07-07 17:48 ` Josh Triplett
2008-07-07 18:09   ` Alexey Zaytsev
2008-07-07 19:42     ` Christopher Li

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).