This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/11736] New: Stackpointer messed up on SuperH


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]