[GHC] #8098: Faulty Word64 arithmetic if optimized
GHC
ghc-devs at haskell.org
Sat Jul 27 22:35:57 CEST 2013
#8098: Faulty Word64 arithmetic if optimized
----------------------------+---------------------------------
Reporter: achp | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.4.2
Keywords: | Operating System: Windows
Architecture: x86 | Type of failure: None/Unknown
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
----------------------------+---------------------------------
The following program produces different results depending on
optimization:
Checked.hs:
{{{
module Checked ((.-.)) where
(.-.) :: (Bounded a, Integral a) => a -> a -> Maybe a
x .-. y | x >= 0 && y < 0 = if z > x then Just z
else Nothing
| x >= 0 = if z <= x then Just z
else Nothing
| x < 0 && y > 0 = if z < x then Just z
else Nothing
| otherwise = Just z
where z = x - y
}}}
Main.hs:
{{{
module Main (main) where
import Data.Maybe
import Data.Word
import Numeric
import Checked
main :: IO ()
main = print $ showHex (fromJust ((0xFFFFFFFF00000000 :: Word64) .-.
0x00000000FFFFFFFF)) ""
}}}
{{{
D:\dev\haskell\ch1>ghc --make Checked.hs Main.hs
[1 of 2] Compiling Checked ( Checked.hs, Checked.o )
[2 of 2] Compiling Main ( Main.hs, Main.o )
Linking Main.exe ...
D:\dev\haskell\ch1>Main.exe
"fffffffe00000001"
D:\dev\haskell\ch1>del *.hi *.o *.exe
D:\dev\haskell\ch1>ghc --make -O2 Checked.hs Main.hs
[1 of 2] Compiling Checked ( Checked.hs, Checked.o )
[2 of 2] Compiling Main ( Main.hs, Main.o )
Linking Main.exe ...
D:\dev\haskell\ch1>Main.exe
"fffe00000001"
D:\dev\haskell\ch1>
}}}
The bug disappears if definition and usage of (.-.) are in the same
module.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8098>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list