public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hjl.tools at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ada/61954] New: Ada fails to properly pass pointer arguments on x32
Date: Tue, 29 Jul 2014 16:23:00 -0000	[thread overview]
Message-ID: <bug-61954-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61954

            Bug ID: 61954
           Summary: Ada fails to properly pass pointer arguments on x32
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com

Pointers in x32 are 32 bits.  When 32-bit pointers passed as argument
in register, they must be zero-extended to 64 bits.  Flush_Buffer in
output.adb has

           if Cur_Indentation = 0
              or else Cur_Indentation + Len > Buffer_Max
              or else Buffer (1 .. Len) = (1 => ASCII.LF)
            then
               Write_Buffer (Buffer (1 .. Len));

which is compiled into:

   0x00797849 <+169>:    lea    -0x40(%rbp),%edi
   0x0079784c <+172>:    movl   $0x1,-0x40(%ebp)
   0x00797854 <+180>:    shl    $0x20,%rdi
   0x00797858 <+184>:    mov    %eax,-0x3c(%ebp)
   0x0079785c <+188>:    mov    $0x1cddf80,%eax
   0x00797861 <+193>:    or     %rax,%rdi
   0x00797864 <+196>:    mov    -0x48(%ebp),%eax
   0x00797868 <+200>:    mov    %rax,-0x60(%ebp)
   0x0079786d <+205>:    mov    $0x1335fd8,%eax
   0x00797872 <+210>:    mov    %rax,-0x50(%ebp)
   0x00797877 <+215>:    mov    $0x1335ff0,%eax
   0x0079787c <+220>:    mov    %rax,-0x58(%ebp)
   0x00797881 <+225>:    callq  0x797530 <output__flush_buffer__write_buffer>

DI register is used to pass a pointer, which should be zero-extended
from 32 bits to 64 bits.  But we got

(gdb) si
0x00797849    136                   Write_Buffer (Buffer (1 .. Len));
(gdb) si
0x0079784c    136                   Write_Buffer (Buffer (1 .. Len));
(gdb) p/x $rdi
$14 = 0xffffcba0
(gdb) si
0x00797854    136                   Write_Buffer (Buffer (1 .. Len));
(gdb) si
0x00797858    136                   Write_Buffer (Buffer (1 .. Len));
(gdb) p/x $rdi
$15 = 0xffffcba000000000
(gdb) 

RTL expand looks strange:

;; D.3473.P_BOUNDS = &D.3474;

(insn 143 142 144 (parallel [
            (set (reg:SI 156)
                (plus:SI (reg/f:SI 78 virtual-stack-vars)
                    (const_int -64 [0xffffffffffffffc0])))
            (clobber (reg:CC 17 flags))
        ]) /export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

(insn 144 143 145 (set (reg:DI 157)
        (zero_extend:DI (reg:SI 156)))
/export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

(insn 145 144 146 (parallel [
            (set (reg:DI 158)
                (ashift:DI (reg:DI 157)
                    (const_int 32 [0x20])))
            (clobber (reg:CC 17 flags))
        ]) /export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

(insn 147 146 148 (parallel [
            (set (reg:DI 160)
                (ior:DI (reg:DI 159)
                    (reg:DI 158)))
            (clobber (reg:CC 17 flags))
        ]) /export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

(insn 148 147 0 (set (reg:DI 120 [ D.3473 ])
        (reg:DI 160)) /export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

;; output.flush_buffer.write_buffer (D.3473);

(insn 149 148 150 (set (reg:DI 5 di)
        (reg:DI 120 [ D.3473 ]))
/export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))


             reply	other threads:[~2014-07-29 16:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-29 16:23 hjl.tools at gmail dot com [this message]
2014-07-30  0:18 ` [Bug ada/61954] " hjl.tools at gmail dot com
2014-07-30  0:34 ` hjl.tools at gmail dot com
2014-07-30 16:03 ` hjl.tools at gmail dot com
2014-08-06 16:30 ` ebotcazou at gcc dot gnu.org

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-61954-4@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).