[GHC] #11704: Word and Int literals not correctly truncated when cross compiling 64 -> 32 bit

GHC ghc-devs at haskell.org
Wed May 18 08:22:09 UTC 2016


#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
      Resolution:                    |             Keywords:  cross-
                                     |  compiling
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
                                     |  codeGen/should_run/T5785
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by thomie):

 * testcase:   => codeGen/should_run/T5785
 * keywords:   => cross-compiling


@@ -31,2 +31,2 @@
- This makes testcase `codeGen/5785.hs` fail when compiled with optimization
- with GHCJS on 64 bit GHC.
+ This makes testcase `codeGen/should_run/T5785` fail when compiled with
+ optimization with GHCJS on 64 bit GHC.

New description:

 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 at .
 -- 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 at .
 -- 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/should_run/T5785` 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#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list