Hi,
the testcase below aborts with gcc 4.1.3 compiled with:
g++ -O2 -fno-threadsafe-statics
=== Cut ===
extern "C" void abort(void);
struct A
{
void *d;
};
static const A& staticA()
{
static A s_static;
return s_static;
}
void assert_failed()
{
abort();
}
A testMethod()
{
static const A& s = staticA( );
if (&s == 0)
assert_failed();
return s;
}
int main()
{
testMethod();
return 0;
}
// g++ -O2 -fno-inline -fno-threadsafe-statics -o kglobaltest kglobaltest.cpp
=== Cut ===
The testcase was extracted from a KDE miscompilation. -fno-schedule-insns2
seems to work around it.
the bug is visible in assembler:
· call· _Z7staticAv· #
· movl· _ZZ10testMethodvE1s, %ebx· # s, s.1
· movb· $1, _ZGVZ10testMethodvE1s· #,
· testl· %ebx, %ebx· # s.1
· movl· %eax, _ZZ10testMethodvE1s· # tmp61, s
the movl %eax,_ZZ10testMethodvE1s is moved below the movl·
_ZZ10testMethodvE1s, %ebx, which causes the bug.
--
Summary: miscompilation with -fschedule-insns2 -fthreadsafe-
statics and static variables
Product: gcc
Version: 4.1.3
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mueller at gcc dot gnu dot org
GCC host triplet: i686-suse-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31806