
#9306: Crash when shifting Integers too much -------------------------------------+------------------------------------ Reporter: dfeuer | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Runtime crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by hvr): The problem here is that the shift amount is of type `Int`, so `fromIntegral (maxBound::Int) + 1` is actually `minBound`, so the code {{{#!hs okay = 1000 `shiftR` (fromIntegral (maxBound::Int) + 1) :: Integer tooFar = 1 `shiftR` (fromIntegral (maxBound::Int) + 2) :: Integer }}} is the same as {{{#!hs okay = 1000 `shiftR` minBound :: Integer tooFar = 1 `shiftR` (minBound + 1) :: Integer }}} And both should have overflowed, as you are effectively requesting a left- shift by a *huge* amount -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9306#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler