From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6215 invoked by alias); 24 Feb 2004 13:35:03 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 6204 invoked by uid 48); 24 Feb 2004 13:35:03 -0000 Date: Tue, 24 Feb 2004 13:35:00 -0000 From: "ehrhardt at mathematik dot uni-ulm dot de" To: gcc-bugs@gcc.gnu.org Message-ID: <20040224133459.14272.ehrhardt@mathematik.uni-ulm.de> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c/14272] New: miscompilation of __exchange_and_add (atomicity.h) X-Bugzilla-Reason: CC X-SW-Source: 2004-02/txt/msg02279.txt.bz2 List-Id: 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