[Haskell-cafe] -O2 bug in GHC 6.8.1?

Brad Clow brad at bjclow.org
Tue Nov 20 06:50:02 EST 2007


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

Here is the transcript from a shell (example code is saved in test.hs):

$ ghc --make test.hs
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...
$ ./test
23
23
$ rm test.hi test.o test
$ ghc -O2 --make test.hs
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...
$ ./test
23
24

It is a little disconcerting that -O2 changes the output. :-)

Regards
brad

-- 
www.scoodi.com
Contribute things you don't need and find things you do, all within
your local community.


More information about the Haskell-Cafe mailing list