From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9234 invoked by alias); 4 Mar 2010 22:23:02 -0000 Received: (qmail 9211 invoked by uid 48); 4 Mar 2010 22:22:51 -0000 Date: Thu, 04 Mar 2010 22:23:00 -0000 Subject: [Bug c++/43263] New: inline asm with -O2 breaks logic if comarisons are involved X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "s dot v dot savenko at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-03/txt/msg00428.txt.bz2 I put here a simple example to illustrate what looks like a bug to me #include inline unsigned next_exp2(unsigned x) { unsigned n; asm volatile("bsr %0, %1" : "=r" (n) : "r" (x)); // most significant bit return((x == (1u << n)) ? n : n); }; inline unsigned next_exp2_(unsigned x) { unsigned n; asm volatile("bsr %0, %1" : "=r" (n) : "r" (x)); // most significant bit return((x == (1u << n)) ? n : n+1); }; int main() { unsigned x = 1025; std::cout << "n1 = " << next_exp2(x) << std::endl; std::cout << "n2 = " << next_exp2_(x) << std::endl; return(0); } The difference between two function is n+1 returned from the underscored version. Compiled with g++ -O2 ./foo.cpp, my output is: n1 = 10 n2 = 3078596801 while I would expect n2 = 11. If I compile it with g++ -g foo.cpp, everything works as expected. -- Summary: inline asm with -O2 breaks logic if comarisons are involved Product: gcc Version: 4.3.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: s dot v dot savenko at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43263