# testcase

typedef volatile unsigned mutex;

void lockMutex(mutex* m)
{
        while (*m != 1);
        *m = 0;
}

void unlockMutex(mutex* m)
{
        *m = 0;
}

*** GCC 3.4.2-20040916 ***

00000000 <lockMutex>:
   0:   e5903000        ldr     r3, [r0]
   4:   e3530001        cmp     r3, #1  ; 0x1
   8:   1afffffe        bne     8 <lockMutex+0x8>    <== should jump to 0x00.
   c:   e2433001        sub     r3, r3, #1      ; 0x1
  10:   e5803000        str     r3, [r0]
  14:   e1a0f00e        mov     pc, lr

00000018 <unlockMutex>:
  18:   e3a03000        mov     r3, #0  ; 0x0
  1c:   e5803000        str     r3, [r0]
  20:   e1a0f00e        mov     pc, lr

*** IAR C compiler ***

lockMutex:
 0x00000180 E5901000  LDR          R1, [R0, #+0]
 0x00000184 E3510001  CMP          R1, #0x1
 0x00000188 1AFFFFFC  BNE          lockMutex  ; 0x180    <=== this works fine.
 0x0000018C E3A01000  MOV          R1, #0x0
 0x00000190 E5801000  STR          R1, [R0, #+0]
 0x00000194 E12FFF1E  BX           LR

unlockMutex:
 0x00000198 E3A01000  MOV          R1, #0x0
 0x0000019C E5801000  STR          R1, [R0, #+0]
 0x000001A0 E12FFF1E  BX           LR


# arm-elf-gcc -v
Reading specs from c:/winarm/bin/../lib/gcc/arm-elf/3.4.2/specs
Configured with: ../../gcc-3.4.2-20040916-1/configure --enable-languages=c,c++
--enable-interwork --enable-multilib --with-gcc --with-gnu-ld --with-gnu-as
--with-stabs --disable-shared --disable-threads --disable-win32-registry
--disable-nls --target=arm-elf --with-newlib
--with-headers=/c/winarms/newlib-1.12.0/newlib/libc/include --prefix=c:/WinARM/
-v : (reconfigured) ../../gcc-3.4.2-20040916-1/configure
--enable-languages=c,c++ --enable-interwork --enable-multilib --with-gcc
--with-gnu-ld --with-gnu-as --with-stabs --disable-shared --disable-threads
--disable-win32-registry --disable-nls --target=arm-elf --with-newlib
--prefix=c:/WinARM/ -v
Thread model: single
gcc version 3.4.2 (mingw-special)

-- 
           Summary: volatile attr. doesn't work with pointers / wrong code
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: other
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at pld-linux dot org
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: mingw
GCC target triplet: arm-elf


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

Reply via email to