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

--- Comment #4 from gidici61 at gmail dot com ---
(In reply to Andrew Pinski from comment #3)
> (In reply to gidici61 from comment #2)
> > Register rsp is correctly aligned before "call g1"; let's assume rsp=0xB0.
> > "call g1" pushes rip (8 bytes) on the stack.  Now rsp=0xA8.
> > Then "pushq %rbp" subtracts 8.  Now rsp=0xA0.
> > "subq $8, %rsp" subtracts 8.  Now rsp=0x98
> > So before calling g2() rsp is not properly aligned.
> 
> call also pushes onto the stack.

If you add "putchar(p1)" in g2(), then rsp become 16-byte aligned before
calling g2():

   int g2(int p1) { putchar(p1); return p1; }            
   int g1(int p1) { return g2(p1); }
   int main()     { return g1(65); }

gives the following assembler code:

g1:
    pushq    %rbp
    movq    %rsp, %rbp
    subq    $16, %rsp           ; OK
    movl    %edi, -4(%rbp)
    movl    -4(%rbp), %eax
    movl    %eax, %edi
    call    g2
    leave
    ret

Reply via email to