[GHC] #13172: scrutinee constant folding produces wrong answer when remapped values are out of bounds

GHC ghc-devs at haskell.org
Mon Jan 23 23:08:15 UTC 2017


#13172: scrutinee constant folding produces wrong answer when remapped values are
out of bounds
-------------------------------------+-------------------------------------
           Reporter:  rwbarton       |             Owner:
               Type:  bug            |            Status:  new
           Priority:  highest        |         Milestone:
          Component:  Compiler       |           Version:  8.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 This program should output 2, but in 8.1 with `-O` enabled it outputs 3.
 The problem is with the way that scrutinee constant folding rewrites the
 case.
 {{{#!hs
 f :: Word -> Word
 f n = case n+1 of
        0 -> 2
        _ -> 3
 {-# NOINLINE f #-}
 main = print (f (-1))
 }}}

 Core with 8.1 and `-O`:
 {{{
 f [InlPrag=NOINLINE] :: Word -> Word
 [GblId, Arity=1, Caf=NoCafRefs, Str=<S(S),1*U(1*U)>m]
 f =
   \ (n_ay2 :: Word) ->
     case n_ay2 of { GHC.Types.W# x#_a1SL ->
     case x#_a1SL of {
       __DEFAULT -> lvl_r4lD;
       -1## -> lvl1_r4mD
     }
     }
 }}}

 Apparently `-1##` isn't okay: it needs to be `9223372036854775807##`.

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


More information about the ghc-tickets mailing list