public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gidici61 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/60926] Compiler doesn't properly align stack pointer
Date: Tue, 22 Apr 2014 21:42:00 -0000	[thread overview]
Message-ID: <bug-60926-4-sSvYsTNPUA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-60926-4@http.gcc.gnu.org/bugzilla/>

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


  parent reply	other threads:[~2014-04-22 21:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-22 21:08 [Bug c/60926] New: " gidici61 at gmail dot com
2014-04-22 21:29 ` [Bug target/60926] " gidici61 at gmail dot com
2014-04-22 21:31 ` pinskia at gcc dot gnu.org
2014-04-22 21:42 ` gidici61 at gmail dot com [this message]
2014-04-22 21:53 ` gidici61 at gmail dot com
2014-04-25 13:45 ` gidici61 at gmail dot com
2014-04-25 15:46 ` hjl.tools at gmail dot com
2014-04-25 16:26 ` gidici61 at gmail dot com
2014-04-25 16:30 ` gidici61 at gmail dot com
2014-04-25 16:40 ` gidici61 at gmail dot com
2014-04-25 17:45 ` hjl.tools at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-60926-4-sSvYsTNPUA@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).