Build command line: gcc -O2 -g -o test test.c

test.c:

#include <stdio.h>
#include <assert.h>

static inline int ILInterlockedCompareAndExchangeI4_Full(volatile int *dest,
                                                                               
                                 int value,
                                                                               
                                 int comparand)
{
        int retval;

        __asm__ __volatile__
        (
                "lock;"
                "cmpxchgl %2, %0"
                : "=m" (*dest), "=a" (retval)
                : "r" (value), "m" (*dest), "a" (comparand)
                : "memory"
        );

        return retval;
}

static inline float ILInterlockedCompareAndExchangeR4_Full(volatile float
*dest,
                                                                               
                                                float value,
                                                                               
                                                float comparand)
{
        int temp;
        void *valuePtr = (void *)&value;
        void *comparandPtr = (void *)&comparand;
        void *tempPtr = (void *)&temp;

        temp = ILInterlockedCompareAndExchangeI4_Full((volatile int *)dest,
                                                                               
                  *(int *)valuePtr,
                                                                               
                  *(int *)comparandPtr);
        return *(float *)tempPtr;
}

float CompareExchangeFloat(float *location1, float value, float comparand)
{
        return ILInterlockedCompareAndExchangeR4_Full(location1, value,
comparand);
}

int main(int argc, char** argv)
{
        float testValue;
        float returnValue;

        testValue = 1.0;
        returnValue = CompareExchangeFloat(&testValue, 2.0, 1.0);

        return (returnValue == 1.0);
}

Function where the code is not genereted correcltly: CompareExchangeFloat

objdump output of the function:

00000000004004f0 <CompareExchangeFloat>:
  4004f0:       8b 54 24 f8             mov    -0x8(%rsp),%edx       <-- value
is read to register
  4004f4:       f3 0f 11 44 24 fc       movss  %xmm0,-0x4(%rsp)
  4004fa:       8b 4c 24 fc             mov    -0x4(%rsp),%ecx
  4004fe:       f3 0f 11 4c 24 f8       movss  %xmm1,-0x8(%rsp)      <-- value
is written to the stack location
  400504:       89 d0                   mov    %edx,%eax             <-- value
is used from register instead of new value from stack location
  400506:       f0 0f b1 0f             lock cmpxchg %ecx,(%rdi)
  40050a:       89 44 24 f4             mov    %eax,-0xc(%rsp)
  40050e:       f3 0f 10 44 24 f4       movss  -0xc(%rsp),%xmm0
  400514:       c3                      retq
  400515:       66 66 2e 0f 1f 84 00    nopw   %cs:0x0(%rax,%rax,1)
  40051c:       00 00 00 00


-- 
           Summary: Value not reread from stack frame
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ktreichel at web dot de
 GCC build triplet: x86_64-suse-linux
  GCC host triplet: x86_64-suse-linux
GCC target triplet: x86_64-suse-linux


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

Reply via email to