public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/11736] New: Stackpointer messed up on SuperH
@ 2003-07-30 22:25 marcus at mc dot pp dot se
  2003-07-30 22:26 ` [Bug target/11736] " marcus at mc dot pp dot se
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: marcus at mc dot pp dot se @ 2003-07-30 22:25 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Stackpointer messed up on SuperH
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: marcus at mc dot pp dot se
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.8
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sh-elf

When a function with 5 arguments is called in both branches of a
conditional, and only the last argument differs, the code to push that
last argument on the stack gets confused.  Example function:

---8<--- r15bug.c ---8<---
extern void bar(int, int, int, int, int); 
 
void foo(int a) 
{ 
  if (a) 
    bar( 0, 0, 0, 0, 1 ); 
  else 
    bar( 0, 0, 0, 0, 0 ); 
} 
---8<---

Compiling with `sh-elf-gcc -O1 -S r15bug.c', I get this:

---8<--- r15bug.s ---8<---
        .file   "r15bug.c" 
        .text 
        .text 
        .align 1 
        .global _foo 
        .type   _foo, @function 
_foo: 
        mov.l   r14,@-r15 
        sts.l   pr,@-r15 
        mov     r15,r14 
        tst     r4,r4 
        add     #-4,r15   ! A
        mov     #1,r1 
        bf      .L4 
        add     #-4,r15   ! B
        mov     #0,r1 
.L4: 
        mov.l   r1,@r15 
        mov     #0,r4 
        mov     #0,r5 
        mov     #0,r6 
        mov.l   .L5,r1 
        jsr     @r1 
        mov     #0,r7
        add     #4,r15 
        mov     r14,r15 
        lds.l   @r15+,pr 
        rts      
        mov.l   @r15+,r14 
.L6: 
        .align 2 
.L5: 
        .long   _bar 
        .size   _foo, .-_foo 
        .ident  "GCC: (GNU) 3.3" 
---8<---

Space for the fifth argument is reserved on the stack by the
instruction I have marked as "A".  However, if the else-branch is
taken the stackpointer is decremented _again_ at "B".  This
decrementation is never restored, and it is only due to the
restoration of r15 from r14 that the function works at all.  With
-fomit-frame-pointer it will crash.


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

end of thread, other threads:[~2004-01-05  8:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-30 22:25 [Bug target/11736] New: Stackpointer messed up on SuperH marcus at mc dot pp dot se
2003-07-30 22:26 ` [Bug target/11736] " marcus at mc dot pp dot se
2003-08-11 12:43 ` pinskia at gcc dot gnu dot org
2003-08-25 16:06 ` dhazeghi at yahoo dot com
2003-08-25 21:46 ` marcus at mc dot pp dot se
2003-08-26  8:03 ` [Bug optimization/11736] " dhazeghi at yahoo dot com
2003-08-26  8:46 ` marcus at mc dot pp dot se
2003-09-15 18:14 ` dank at kegel dot com
2004-01-05  0:27 ` kazu at cs dot umass dot edu
2004-01-05  8:18 ` kazu at cs dot umass dot edu

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).