[Bug c/14272] New: miscompilation of __exchange_and_add (atomicity.h)
ehrhardt at mathematik dot uni-ulm dot de
gcc-bugzilla@gcc.gnu.org
Tue Feb 24 13:35:00 GMT 2004
The following piece of code (destilled from atomicity.h in
libstdc++-v3) is miscompiled by tree-ssa with -O2 on a sparc-sun-solaris2.9
platform (probably arch independant). The code outputs BUG!!! where
it clearly shouldn't. This works with C and C++.
====================== cut =============================
extern int printf (const char *, ...);
int __attribute__ ((__noinline__))
__exchange_and_add (volatile int* __mem, int __val)
{
int __result, __tmp;
__result = *__mem;
*__mem += __val;
return __result;
}
int data = 0;
int main ()
{
if (__exchange_and_add (&data, 1) != 0) {
printf ("BUG!!!\n");
}
return 0;
}
====================== cut =============================
The consequences in the context of libstdc++ on sparc-sun-solaris are
that std::cout and friends are never initialized, i.e. not even a hello
world program runs. Note that the volatile keyword is crucial, removing
it makes the bug go away. The wrong code first appears in .t35.optimized.
regards Christian
--
Summary: miscompilation of __exchange_and_add (atomicity.h)
Product: gcc
Version: tree-ssa
Status: UNCONFIRMED
Keywords: wrong-code
Severity: critical
Priority: P1
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ehrhardt at mathematik dot uni-ulm dot de
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14272
More information about the Gcc-bugs
mailing list