logo       

[GHC] #765: x86_64 NCG goes via unsigned for FFI Int return types.: msg#00035

lang.haskell.glasgow.bugs

Subject: [GHC] #765: x86_64 NCG goes via unsigned for FFI Int return types.

#765: x86_64 NCG goes via unsigned for FFI Int return types.
--------------------------------------------+-------------------------------
Reporter: duncan.coutts@xxxxxxxxxxxxx | Owner:
Type: bug | Status: new
Priority: high | Milestone:
Component: Compiler (NCG) | Version: 6.4.2
Severity: normal | Keywords:
Os: Linux | Difficulty: Unknown
Architecture: x86_64 (amd64) |
--------------------------------------------+-------------------------------
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.

--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/765>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise