From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1454 invoked by alias); 29 Jul 2014 16:23:32 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 12447 invoked by uid 48); 29 Jul 2014 16:10:18 -0000 From: "hjl.tools at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ada X-Bugzilla-Version: 4.10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hjl.tools at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-07/txt/msg01925.txt.bz2 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 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))