Skip to content

Native Code gen miscompiles double2Int# / float2Int# on x86_32

Brad Clow: I upgraded from GHC 6.6.1 to 6.8.1 and around that time I noticed that the output from an app I am working on changed. I have distilled the code down to the following example that produces different output depending on whether it is compiled with -O2 or not:

main = do
    let (T x) = read "T 3"
    print $ f x
    print $ g x

data T = T Int deriving (Read, Show)

f x = truncate $ 2000 / fromIntegral ((x * 25) + 10)

g :: Int -> Int
g x = f x

(See http://www.haskell.org/pipermail/haskell-cafe/2007-November/034930.html)

The reason is that the code generated for double2Int# by the native code generator does not round correctly. (It's not 100% predictable, I believe, but it'll usually round.)

Trac metadata
Trac field Value
Version 6.8.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information