This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
IMA corner case with forward declarations of statics
- From: Zack Weinberg <zack at codesourcery dot com>
- To: gcc at gcc dot gnu dot org, Geoff Keating <geoffk at geoffk dot org>, Andrew Pinski<apinski at apple dot com>
- Date: Wed, 23 Jun 2004 19:43:06 -0700
- Subject: IMA corner case with forward declarations of statics
Consider the following test case:
A.c:
int foo = 12;
B.c:
extern int printf(const char *, ...);
extern int foo;
int main(void)
{
printf("%d\n", foo);
return 0;
}
static int foo = 14;
Taken together, this is a correct C program which should print 14.
However, I've discovered that when compiled with the present
implementation of IMA (i.e. my locally patched tree) it only prints 14
if you give the files in the order B.c A.c.
If you give the files in the order A.c B.c, the 'extern int foo'
declaration is unified with the 'int foo = 12' from A.c the moment
it's encountered. Then when we encounter the static, it shadows the
declaration in the external scope, but it's too late for main, which
has already been saved with a reference to the original foo in its
parse tree.
Now, GCC 3.4's IMA doesn't do the right thing with this either; no
matter which order the files are given in, you get
Assembler messages:
Error: symbol `foo' is already defined
No one has noticed, which leads me to believe that this will not be a
problem in real life. So I propose to detect the case where we would
generate incorrect code, and call sorry() instead.
zw