
#11704: Word and Int literals not correctly truncated when cross compiling 64 -> 32 bit -------------------------------------+------------------------------------- Reporter: luite | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1-rc2 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: -------------------------------------+------------------------------------- GHC does not take the target word size into account for some of the rules in `PrelRules`: {{{#!hs rule_convert "integerToWord" integerToWordName mkWordLitWord, rule_convert "integerToInt" integerToIntName mkIntLitInt, }}} The relevant code from `CoreSyn`: {{{#!hs -- | Create a machine word literal expression of type @Word#@ from a @Word@. -- If you want an expression of type @Word@ use 'MkCore.mkWordExpr' mkWordLitWord :: DynFlags -> Word -> Expr b mkWordLit dflags w = Lit (mkMachWord dflags w) mkWordLitWord dflags w = Lit (mkMachWord dflags (toInteger w)) -- | Create a machine integer literal expression of type @Int#@ from an @Int@. -- If you want an expression of type @Int@ use 'MkCore.mkIntExpr' mkIntLitInt :: DynFlags -> Int -> Expr b mkIntLitInt dflags n = Lit (mkMachInt dflags (toInteger n)) }}} If a literal is bigger than the target word size, these rules can lead to loss of truncation when optimizing a `fromInteger` / `toInteger` pair. This makes testcase `codeGen/5785.hs` fail when compiled with optimization with GHCJS on 64 bit GHC. It probably also affects targeting 64 platforms with 32 bit compilers, where literals would be truncated too much, but I don't have a way of testing that. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11704 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler