http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
--- Comment #1 from brag <unixoid2003 at mail dot ru> 2012-04-23 12:58:17 UTC --- struct aa{ volatile unsigned short a; unsigned short b; volatile unsigned short c; unsigned short d; }; #define AAmem ((struct aa *) 256) static inline unsigned int tx(unsigned int v){ while(AAmem->a&1); AAmem->c=v; while(AAmem->a&2); v=AAmem->c; return v; } void f(){ tx(0xff); tx(0xff); } Compiled by: arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O2 -fomit-frame-pointer -ffreestanding -fno-common -Wall -Wextra -x c -c test.cpp OR arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O2 -fomit-frame-pointer -ffreestanding -fno-common -Wall -Wextra -x c++ -c test.cpp The code generated is wrong. There should be two writes to AAmem->c bute there is one write (strh r3, [r2, #4]) arm-none-eabi-objdump -d test.o : test.o: file format elf32-littlearm Disassembly of section .text: 00000000 <f>: 0: f44f 7180 mov.w r1, #256 ; 0x100 4: 880b ldrh r3, [r1, #0] 6: f44f 7280 mov.w r2, #256 ; 0x100 a: 07d8 lsls r0, r3, #31 c: d4fa bmi.n 4 <f+0x4> e: 23ff movs r3, #255 ; 0xff 10: 8093 strh r3, [r2, #4] 12: 4611 mov r1, r2 14: 880b ldrh r3, [r1, #0] 16: f44f 7280 mov.w r2, #256 ; 0x100 1a: f003 0302 and.w r3, r3, #2 1e: b29b uxth r3, r3 20: 2b00 cmp r3, #0 22: d1f7 bne.n 14 <f+0x14> 24: 8893 ldrh r3, [r2, #4] 26: 8813 ldrh r3, [r2, #0] 28: 07db lsls r3, r3, #31 2a: d4fc bmi.n 26 <f+0x26> 2c: f44f 7280 mov.w r2, #256 ; 0x100 30: 8813 ldrh r3, [r2, #0] 32: f003 0302 and.w r3, r3, #2 36: b29b uxth r3, r3 38: 2b00 cmp r3, #0 3a: d1f9 bne.n 30 <f+0x30> 3c: f44f 7380 mov.w r3, #256 ; 0x100 40: 889b ldrh r3, [r3, #4] 42: 4770 bx lr