Opened 2 years ago

Closed 2 years ago

#7383 closed bug (fixed)

implement proper type promotion in compilation of C calls

Reported by: igloo Owned by:
Priority: high Milestone: 7.6.2
Component: Compiler Version: 7.6.1
Keywords: Cc: johan.tibell@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: 7684 Differential Revisions:

Description

> commit 229323898b0809047b19b79c181085430cce9850
> Author: Ian Lynagh <[email protected]>
> Date:   Thu Nov 1 14:13:05 2012 +0000
>
>      Fix popcnt calls
>
>      We don't want to narrow the argument size before making the foreign
>      call: Word8 still gets passed as a Word-sized argument

I'm not sure this is right (I added the narrowing, FWIW).  The fact that
Word8 gets promoted to Word is part of the C ABI, and we don't want to
do that when popcnt is being implemented directly by the native codegen.
  I know it is currently broken on some platforms, but I think the fix
is to implement the proper type promotion in the compilation of C calls.

A useful test for this is cgrun071. If we get it wrong then it fails on x86, as the stack alignment is wrong when calling e.g. popCnt8#.

Attachments (1)

0001-x86-promote-arguments-to-C-functions-according-to-th.patch (3.6 KB) - added by simonmar 2 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 2 years ago by igloo

  • Milestone changed from 7.8.1 to 7.6.2

comment:2 Changed 2 years ago by tibbe

cgrun071 now segfaults. See linked ticket.

comment:3 Changed 2 years ago by tibbe

  • Cc johan.tibell@… added

comment:4 Changed 2 years ago by simonmar

  • Status changed from new to infoneeded

Please try the attached patch. It validates for me on x86-64/Linux, but I don't think it affects anything there.

comment:5 Changed 2 years ago by marlowsd@…

commit 085e8145f63c8f42d8bc19cd3cff52b8cd5b6455

Author: Simon Marlow <[email protected]>
Date:   Wed Feb 20 11:43:33 2013 +0000

    x86: promote arguments to C functions according to the ABI (#7383)
    
    I don't think the x86-64 version is quite right, but this ought to be
    enough to pass cgrun071.
    
    This code is terrible and needs a complete refactor.  There's a lot of
    duplication, and we ought to be specifying the ABI in a much more
    abstract way (like LLVM).

 compiler/nativeGen/X86/CodeGen.hs |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

comment:6 Changed 2 years ago by igloo

  • Resolution set to fixed
  • Status changed from infoneeded to closed

cgrun071 passes on OS X x86. I've pushed it.

Note: See TracTickets for help on using tickets.