Opened 9 years ago

Closed 9 years ago

#765 closed bug (invalid)

x86_64 NCG goes via unsigned for FFI Int return types.

Reported by: duncan.coutts@… Owned by:
Priority: high Milestone:
Component: Compiler (NCG) Version: 6.4.2
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

With ghc-6.4.2 on x86_64 and using the -fasm NCG we get the wrong answer for this FFI test case:

cbit.c:

int c_id (int n) {
        return n;
}

hsbit.hs:

module Foo where
foreign import ccall unsafe "c_id" c_id :: Int -> IO Int
ghc -c cbit.c
ghc -fffi --make test.hs cbit.o
./a.out
4294967295

Going via C we get the correct answer:

ghc -fvia-C -fffi --make test.hs cbit.o
/tmp/ghc32363.hc:135: warning: implicit declaration of function `c_id'
./a.out
-1

Obviously what's going on is that we're converting to an unsigned int value at some point so negative values are wrapping round.

Change History (2)

comment:1 Changed 9 years ago by guest

Note that if we declare the foreign import with CInt then we get the right answer.

foreign import ccall unsafe "c_id" c_id :: CInt -> IO CInt

comment:2 Changed 9 years ago by simonmar

  • Resolution set to invalid
  • Status changed from new to closed

This isn't a bug: the Haskell Int type corresponds to HsInt, not int, in C land. As noted, CInt works correctly.

Note: See TracTickets for help on using tickets.