Hello. I've found bug in GCC 4.4.1 for ARM7TDMI in THUMB mode. Test code: void foo(char *bar); char test() { char tmp; foo(&tmp); return tmp; } Compiled with: arm-elf-gcc -S -mcpu=arm7tdmi -O2 -mthumb test.c Then using -O2 or -O3 optimization, assembler code looks like: 1:test: 2: push {r4, lr} 3: sub sp, sp, #4 4: mov r4, sp 5: add r4, r4, #3 6: mov r0, r4 7: bl foo 8: add sp, sp, #4 9: ldrb r0, [r4] 10: @ sp needed for prologue 11: pop {r4, pc} So, if interrupt or task switching occurs between line 8 and line 9, local variable in stack (referenced by r4) will be garbaged by service routine, because stack rewinds before usage of local variable. This code works fine with -O1: 1:test: 2: push {r4, lr} 3: sub sp, sp, #4 4: mov r4, sp 5: add r4, r4, #3 6: mov r0, r4 7: bl foo 8: ldrb r0, [r4] 9: add sp, sp, #4 10: @ sp needed for prologue 11: pop {r4, pc}
*** This bug has been marked as a duplicate of 38644 ***