[GHC] #10521: Wrong results in strict Word8 storage on x64

GHC ghc-devs at haskell.org
Sun Jun 14 19:55:08 UTC 2015


#10521: Wrong results in strict Word8 storage on x64
-------------------------------------+-------------------------------------
              Reporter:              |             Owner:
  VincentBerthoux2                   |            Status:  new
                  Type:  bug         |         Milestone:
              Priority:  normal      |           Version:  7.10.1
             Component:  Compiler    |  Operating System:  Unknown/Multiple
              Keywords:              |   Type of failure:  Incorrect result
          Architecture:  x86_64      |  at runtime
  (amd64)                            |        Blocked By:
             Test Case:              |   Related Tickets:
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------
 The following snippet produce two different results in function of the
 compiler platform used:

 {{{#!hs
 import Data.Word( Word8 )

 -- removing the bang patterns on V definition makes
 -- the problem go away.
 data V = V !Word8 !Word8 deriving Show

 toV :: Float -> V
 toV d = V (truncate $ d * coeff) (fromIntegral $ exponent d + 128) where
   coeff = significand d *  255.9999 / d

 main :: IO ()
 main =
   print $ map toV [ 3.56158e-2, 0.7415215, 0.5383201, 0.1289829,
 0.45520145 ]
 }}}

 On GHC 7.10.1 x86 (under windows and Linux) the output is:
 {{{
 [V 145 124,V 189 128,V 137 128,V 132 126,V 233 127]
 }}}

 On GHC 7.10.1 x64 (under windows and Linux), the (invalid) output is:
 {{{
 [V 0 124,V 0 128,V 0 128,V 0 126,V 0 127]
 }}}

 The bug appear at the following optimisation levels:

  - {{{-O1}}}
  - {{{-O2}}}
  - {{{-O3}}}

 the results are the same at {{{-O0}}}

 This bug was discovered in a bug report in the library JuicyPixels
 [https://github.com/Twinside/Juicy.Pixels/issues/98].

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10521>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list