Certain read accesses to objects marked as "volatile" are optimized away. This happens when both "-O2" and "-fno-strict-aliasing" are specified. This has been observed with the Linux kernel which is unusable in certain configurations due to this problem. This used to work with 3.4.0.
Environment: System: Linux macro 2.4.26 #3 Thu May 6 20:57:18 CEST 2004 i686 unknown unknown GNU/Linux Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: mips64el-unknown-linux-gnu configured with: ../configure --prefix=/usr --enable-languages=c --disable-libmudflap --disable-shared --target=mips64el-linux How-To-Repeat: The following program can be used: $ cat volatile.c struct data { volatile unsigned long *addr; } *p; int test() { *p->addr; return 0; } $ mips64el-linux-gcc -mabi=32 -O2 -fno-strict-aliasing -mno-abicalls -S volatile.c -o volatile.s $ cat volatile.s .file 1 "volatile.c" .section .mdebug.abi32 .previous .text .align 2 .align 2 .globl test .ent test .type test, @function test: .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0 .mask 0x00000000,0 .fmask 0x00000000,0 .set noreorder .set nomacro j $31 move $2,$0 .set macro .set reorder .end test .comm p,4,4 .ident "GCC: (GNU) 3.5.0 20040726 (experimental)" After removing the "-fno-strict-aliasing" option, the output is correct: $ mips64el-linux-gcc -mabi=32 -O2 -mno-abicalls -S volatile.c -o volatile.s $ cat volatile.s .file 1 "volatile.c" .section .mdebug.abi32 .previous .text .align 2 .align 2 .globl test .ent test .type test, @function test: .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0 .mask 0x00000000,0 .fmask 0x00000000,0 .set noreorder .set nomacro lui $2,%hi(p) lw $4,%lo(p)($2) move $2,$0 lw $3,0($4) nop lw $5,0($3) j $31 nop .set macro .set reorder .end test .comm p,4,4 .ident "GCC: (GNU) 3.5.0 20040726 (experimental)" ------- Additional Comments From macro at linux-mips dot org 2004-07-26 18:11 ------- Fix: None known. Using "-fstrict-aliasing" may be a workaround, but it is not an option for Linux. -- Summary: Accesses to volatile objects optimized away with -fno- strict-aliasing Product: gcc Version: 3.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: macro at linux-mips dot org CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: mips64el-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16721