Compiling the test code with optimizations enabled generates invalid code. Data gets read from the source table but gets not written to the destination.
Test code: /* start of test.c */ /* compile: arm-elf-gcc -Os -c -o test.o test.c */ /* dump: arm-elf-objdump -D test.o | more */ typedef unsigned int u_int32_t; typedef unsigned char u_int8_t; #define AIC_VECTORS 32 typedef volatile struct AT91RM9200_AIC { u_int32_t SVR[AIC_VECTORS]; } AT91RM9200_AIC_t; typedef volatile struct AT91RM9200_regs { AT91RM9200_AIC_t AIC; } AT91RM9200_regs_t; #define CPUReg ((AT91RM9200_regs_t*)0xFFF00000) extern const u_int32_t __IntTable[AIC_VECTORS]; int main() { int c; AT91RM9200_AIC_t *aic = &CPUReg->AIC; for (c=0; c < AIC_VECTORS; c++) { aic->SVR[c] = __IntTable[c]; } return 0; } /* end of test.c */ objdump output: test.o: file format elf32-littlearm Disassembly of section .text: 00000000 <main>: 0: e59f2014 ldr r2, [pc, #20] ; 1c <.text+0x1c> 4: e59f3014 ldr r3, [pc, #20] ; 20 <.text+0x20> 8: e2822004 add r2, r2, #4 ; 0x4 c: e1520003 cmp r2, r3 10: 1affffff bne 4 <main+0x4> 14: e3a00000 mov r0, #0 ; 0x0 18: e12fff1e bx lr As you can see, there is no store (str) instruction at all. Code just goes through the __IntTable[] but does nothing useful. -- Summary: Generates wrong code (w/ optimization) when copying data from a table to a table in a structure Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: critical Priority: P1 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sami dot kantoluoto at embedtronics dot fi CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i386-unknown-netbsdelf2.0 GCC host triplet: i386-unknown-netbsdelf2.0 GCC target triplet: arm-unknown-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21171