--- Comment #1 from pinskia at gmail dot com 2009-12-30 13:14 ---
Subject: Re: New: wrong code with -O1
Sent from my iPhone
On Dec 30, 2009, at 7:56 AM, debian-gcc at lists dot debian dot org
gcc-bugzi...@gcc.gnu.org
wrote:
current trunk/branches on x86_64-linux-gnu. return values with
different
compilers and different optimizations:
-O0 -O1 -O2 -O3
gcc-4.1 0222
gcc-4.3 0222
gcc-4.4 2000
gcc-4.5 0100
Matthias
#include stdbool.h
#include stdio.h
static bool atomic_test_and_reset_bit(unsigned long *v,unsigned long
bit) {
bool res;
__asm__ __volatile__( btr %2,%1\n
adc $0,%0\n
:=r(res), =m(*v)
:r(bit), r(0)) ;
return res ? 1 : 0;
This inline-asm looks wrong. Because it says *v is always overriden.
So if that function is inlined, flags down below does not have to be
set before it.
}
int main(void)
{
unsigned long flags = 0;
int j;
j = atomic_test_and_reset_bit(flags, 2);
printf(%d\n, j);
return 0;
}
--
Summary: wrong code with -O1
Product: gcc
Version: 4.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: debian-gcc at lists dot debian dot org
GCC target triplet: x86_64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42553
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42553