Skip to content

GHC wraps Int64 literals on 32-bit platforms when optimizing code (only happens on LLVM/C backends)

Summary

GHC wraps Int64 literals on 32-bit platforms when enabling optimizations. This only happens on LLVM/C backends, and not with NCG. I have reproduced this issue in the following environments:

  • GHC 9.8.2 on X86 with the LLVM backend
  • Unregisterised GHC 9.8.2 on X86 (i.e., using the C backend)
  • GHC 9.4.7 on armel from Debian (uses the LLVM backend)

Steps to reproduce

$ cat Bug.hs
import Data.Int

main = do
  input <- getLine
  let d = (read input :: Int64)
  print (d - 3000000000::Int64)

$ ghc -fllvm -o bug Bug.hs
$ echo 0 | ./bug
-3000000000

$ ghc -fllvm -o bug Bug.hs -O
$ echo 0 | ./bug
1294967296
Edited by Ilias Tsitsimpis
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information