This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: Problem with local static variable guards with old ABI
- To: gcc-patches at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org
- Subject: C++ PATCH: Problem with local static variable guards with old ABI
- From: scott snyder <snyder at fnal dot gov>
- Date: Tue, 04 Jul 2000 01:55:27 CDT
hi -
A recent cvs version of gcc (20000703) on an i686-pc-linux platform
screws up the guards for local static variables when the old ABI is
being used.
Here's an example:
-- x1.cc --------------------------------------------------------------
extern "C" void puts (const char*);
struct S
{
S () { puts ("S ctor"); }
};
void foo ()
{
puts ("foo");
static S s;
}
extern void bar ();
int main ()
{
foo ();
bar ();
return 0;
}
-- x2.cc --------------------------------------------------------------
extern "C" void puts (const char*);
struct S
{
S () { puts ("S ctor"); }
};
void bar ()
{
puts ("bar");
static S s;
}
-----------------------------------------------------------------------
Compile these two and link them together:
$ g++ -o x x1.cc x2.cc
$ ./x
foo
S ctor
bar
Note the S constructor is called only once, even though two objects
are created.
Here are the relevant excerpts from the assembly output for x1.cc:
gcc2_compiled.:
.local s.0
.comm s.0,1,1
.local _.tmp_0.1
.comm _.tmp_0.1,4,4
.comm __sns.0,4,4
...
foo__Fv:
cmpl $0, __sns.0
jne .L4
subl $12, %esp
pushl $s.0
call __1S
addl $16, %esp
movl %eax, -4(%ebp)
movl $1, __sns.0
.L4:
Here, the symbol __sns.0 is being used as the guard. However,
it is not declared .local --- so one instance of the guard gets
shared between the two compilation units!
I think this is the fix:
2000-07-04 scott snyder <snyder@fnal.gov>
* decl2.c (get_guard): Add missing return for old ABI local
variable case.
Index: decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.375
diff -u -p -c -p -r1.375 decl2.c
*** decl2.c 2000/07/03 15:43:49 1.375
--- decl2.c 2000/07/04 06:35:09
*************** get_guard (decl)
*** 2874,2879 ****
--- 2874,2880 ----
{
guard = get_temp_name (integer_type_node);
rest_of_decl_compilation (guard, NULL_PTR, 0, 0);
+ return guard;
}
if (!flag_new_abi)