User account creation filtered due to spam.

Bug 42155 - Optimizer generates bad code for ARM7 THUMB mode (local variable lost)
Summary: Optimizer generates bad code for ARM7 THUMB mode (local variable lost)
Status: RESOLVED DUPLICATE of bug 38644
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-23 15:17 UTC by Alexey Presniakov
Modified: 2009-11-23 16:42 UTC (History)
5 users (show)

See Also:
Host: i486-linux-gnu
Target: arm-elf
Build: arm-elf
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Presniakov 2009-11-23 15:17:57 UTC
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}
Comment 1 Andrew Pinski 2009-11-23 16:42:08 UTC

*** This bug has been marked as a duplicate of 38644 ***