[GHC] #16111: Inconsistent behavior of Data.Bits.shiftL with different optimization levels and -fllvm
GHC
ghc-devs at haskell.org
Sun Dec 30 17:04:50 UTC 2018
#16111: Inconsistent behavior of Data.Bits.shiftL with different optimization
levels and -fllvm
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.3
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: Incorrect result
Unknown/Multiple | at runtime
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
Consider this program:
{{{#!hs
module Main (main) where
import Data.Bits
import Data.Word
main :: IO ()
main = print $ toInteger (shiftL 1 hm :: Word64)
== toInteger (shiftL 1 hm :: Word64)
hm :: Int
hm = -1
{-# NOINLINE hm #-}
}}}
The result of this program depends greatly on what optimization levels are
used, and whether `-fllvm` is used:
{{{
$ /opt/ghc/8.6.3/bin/ghc -fforce-recomp -O0 Bug.hs && ./Bug
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Linking Bug ...
True
$ /opt/ghc/8.6.3/bin/ghc -fforce-recomp -O1 Bug.hs && ./Bug
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Linking Bug ...
True
$ /opt/ghc/8.6.3/bin/ghc -fforce-recomp -O2 Bug.hs && ./Bug
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Linking Bug ...
Bug: Bad shift length-1
$ /opt/ghc/8.6.3/bin/ghc -fforce-recomp -O0 -fllvm Bug.hs && ./Bug
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Linking Bug ...
True
$ /opt/ghc/8.6.3/bin/ghc -fforce-recomp -O1 -fllvm Bug.hs && ./Bug
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Linking Bug ...
False
$ /opt/ghc/8.6.3/bin/ghc -fforce-recomp -O2 -fllvm Bug.hs && ./Bug
[1 of 1] Compiling Main ( Bug.hs, Bug.o )
Linking Bug ...
Bug: Bad shift length-1
}}}
This program manages to return all of `True`, `False`, and `Bad shift
length-1` depending on which flags are used!
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16111>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list