public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/14272] New: miscompilation of __exchange_and_add (atomicity.h)
@ 2004-02-24 13:35 ehrhardt at mathematik dot uni-ulm dot de
  2004-02-24 14:26 ` [Bug optimization/14272] [tree-ssa] " pinskia at gcc dot gnu dot org
                   ` (20 more replies)
  0 siblings, 21 replies; 23+ messages in thread
From: ehrhardt at mathematik dot uni-ulm dot de @ 2004-02-24 13:35 UTC (permalink / raw)
  To: gcc-bugs

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


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

end of thread, other threads:[~2004-02-26 15:43 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-24 13:35 [Bug c/14272] New: miscompilation of __exchange_and_add (atomicity.h) ehrhardt at mathematik dot uni-ulm dot de
2004-02-24 14:26 ` [Bug optimization/14272] [tree-ssa] " pinskia at gcc dot gnu dot org
2004-02-24 14:48 ` ehrhardt at mathematik dot uni-ulm dot de
2004-02-25 12:40 ` steven at gcc dot gnu dot org
2004-02-25 13:32 ` steven at gcc dot gnu dot org
2004-02-25 13:43 ` steven at gcc dot gnu dot org
2004-02-25 14:02   ` Christian Ehrhardt
2004-02-25 14:02 ` ehrhardt at mathematik dot uni-ulm dot de
2004-02-25 14:06 ` amacleod at redhat dot com
2004-02-25 14:08 ` dnovillo at redhat dot com
2004-02-25 18:06 ` dnovillo at redhat dot com
2004-02-25 18:20 ` amacleod at redhat dot com
2004-02-25 19:53 ` dnovillo at redhat dot com
2004-02-25 19:54 ` dnovillo at redhat dot com
2004-02-26 10:19 ` steven at gcc dot gnu dot org
2004-02-26 13:07 ` dnovillo at gcc dot gnu dot org
2004-02-26 14:56 ` ehrhardt at mathematik dot uni-ulm dot de
2004-02-26 14:59 ` dnovillo at redhat dot com
2004-02-26 14:59 ` amacleod at redhat dot com
2004-02-26 15:00 ` ehrhardt at mathematik dot uni-ulm dot de
2004-02-26 15:02 ` ehrhardt at mathematik dot uni-ulm dot de
2004-02-26 15:15 ` amacleod at redhat dot com
2004-02-26 15:43 ` ehrhardt at mathematik dot uni-ulm dot de

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 read-only IMAP folder(s) and NNTP newsgroup(s).