[GHC] #10215: Optimizer has bugs regarding handling of -0.0

GHC ghc-devs at haskell.org
Sun Mar 29 23:28:18 UTC 2015


#10215: Optimizer has bugs regarding handling of -0.0
-------------------------------------+-------------------------------------
              Reporter:  lerkok      |             Owner:
                  Type:  bug         |            Status:  new
              Priority:  high        |         Milestone:
             Component:  Compiler    |           Version:  7.8.3
              Keywords:              |  Operating System:  Unknown/Multiple
          Architecture:              |   Type of failure:  Incorrect result
  Unknown/Multiple                   |  at runtime
             Test Case:              |        Blocked By:
              Blocking:              |   Related Tickets:  #9238
Differential Revisions:              |
-------------------------------------+-------------------------------------
 This is most likely related to
 https://ghc.haskell.org/trac/ghc/ticket/9238

 Perhaps it can be merged into that if it is indeed the case, though it'd
 be good for an expert to take a look and make sure first that the culprit
 is indeed the same. In any case, the program in this ticket can at least
 serve as a test-case.

 I observed this on 7.8.3; though I suspect the same holds in the just
 released 7.10.1 as well.
 For the following program:

 {{{#!hs
 testF :: Float -> Bool
 testF x = x == 0 && not (isNegativeZero x)

 testD :: Double -> Bool
 testD x = x == 0 && not (isNegativeZero x)

 main :: IO ()
 main = do print $ testF (-0.0)
           print $ testD (-0.0)
 }}}

 If I compile with no optimizations, then I get the correct answers:
 {{{
 $ /bin/rm -f a.hi a.o a; ghc -O0 a; ./a
 [1 of 1] Compiling Main             ( a.hs, a.o )
 Linking a ...
 False
 False
 }}}

 But if I turn optimizations on, then I get:
 {{{
 $ /bin/rm -f a.hi a.o a; ghc -O2 a; ./a
 [1 of 1] Compiling Main             ( a.hs, a.o )
 Linking a ...
 True
 True
 }}}

 which is just plain wrong.

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


More information about the ghc-tickets mailing list