[Bug rtl-optimization/42155] New: Optimizer generates bad code for ARM7 THUMB mode (local variable lost)
heavy at smtp dot ru
gcc-bugzilla@gcc.gnu.org
Mon Nov 23 15:18:00 GMT 2009
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}
--
Summary: Optimizer generates bad code for ARM7 THUMB mode (local
variable lost)
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: heavy at smtp dot ru
GCC build triplet: arm-elf
GCC host triplet: i486-linux-gnu
GCC target triplet: arm-elf
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42155
More information about the Gcc-bugs
mailing list