Hi, Please take a look at the testcase faadd.c: -------------------------------------------------------------- int foo (int * p, int i) { return __sync_fetch_and_add(p, i); }
int n = 1; int main() { printf("%d %d\n", foo (&n, n), n); return 0; } -------------------------------------------------------------- It is expected to print "1 2". However gcc 4.4.0 for i386-solaris prints "1 1" for it. # gcc faadd.c -march=i686 faadd.c: In function 'main': faadd.c:9: warning: incompatible implicit declaration of built-in function 'printf' # ./a.out 1 1 # gcc -v Using built-in specs. Target: i386-pc-solaris2.11 Configured with: /import/iropt5/lijuan/plain-gcc/gcc-git/configure --prefix=/import/dr3/i386/gcc-4.4.0 --enable-shared --disable-static --disable-libtool-lock --disable-libada --enable-libssp --enable-languages=c,c++,objc,fortran --enable-threads=posix --enable-tls=yes --with-system-zlib --without-gnu-ld --with-ld=/usr/ccs/bin/ld --with-as=/usr/sfw/bin/gas --enable-c99 --enable-nls --enable-wchar_t --enable-libstdcxx-allocator=mt --with-pic --disable-bootstrap Thread model: posix gcc version 4.4.0 20090421 (prerelease) (GCC) # uname -a SunOS gcc-v20z-s04 5.11 snv_102 i86pc i386 i86pc The assembly code for foo looks like as follows: foo: pushl %ebp movl %esp, %ebp movl 12(%ebp), %edx movl 8(%ebp), %eax lock xaddl %edx, (%eax) movl %edx, %eax popl %ebp ret I have also tried running it on other hosts. x86-solaris and x86-Linux both printed "1 1" while sparc and powerpc machines both printed "1 2". Is it a real defect agains gcc for x86-solaris or something wrong with -march? Thanks a lot, -- Lijuan -- Summary: __sync_fetch_and_add seems not working well for - march=i686 Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hailijuan at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40471