This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug inline-asm/11935] New: code using __asm__ shows incorrect behavior when compiled with -O1 flags


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11935

           Summary: code using __asm__ shows incorrect behavior when
                    compiled with -O1 flags
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rajesh dot rajamani at siebel dot com
                CC: gcc-bugs at gcc dot gnu dot org

g++ -o inc inc.cpp
./inc
j is 10
j is 11, k is 11

g++ -O1 -o inc inc.cpp
j is 10
j is 11, k is 8

----------inc.cpp------------
#include <iostream>
#include <stdio.h>

/** Atomic increment/decrement implementation
 ** using __asm__ interface by Rajesh Rajamani
 **/

unsigned long atomic_inc(unsigned long* t) {

        unsigned long rval;
        __asm__ __volatile__ ("
                               movl $0x1,%0
                               lock;
                               xadd %0,(%1)
                               incl %0
                               "
                              :"=d"(rval)
                              :"c"(t)
                        );
}

int main (void) {

        unsigned long int k;
        static unsigned long j = 10;
        printf("j is %d\n",j);
        k = atomic_inc(&j);
        printf("j is %d, k is %d \n",j,k);
        return 0;
}
----------inc.cpp------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]