public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/42155]  New: Optimizer generates bad code for ARM7 THUMB mode (local variable lost)
@ 2009-11-23 15:18 heavy at smtp dot ru
  2009-11-23 16:42 ` [Bug rtl-optimization/42155] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: heavy at smtp dot ru @ 2009-11-23 15:18 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug rtl-optimization/42155] Optimizer generates bad code for ARM7 THUMB mode (local variable lost)
  2009-11-23 15:18 [Bug rtl-optimization/42155] New: Optimizer generates bad code for ARM7 THUMB mode (local variable lost) heavy at smtp dot ru
@ 2009-11-23 16:42 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-11-23 16:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-11-23 16:42 -------


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


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42155


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-11-23 16:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-23 15:18 [Bug rtl-optimization/42155] New: Optimizer generates bad code for ARM7 THUMB mode (local variable lost) heavy at smtp dot ru
2009-11-23 16:42 ` [Bug rtl-optimization/42155] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).