summaryrefslogtreecommitdiff
path: root/compiler/GHC/HsToCore
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-11-02 14:42:07 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-11-03 17:42:26 -0500
commit37f0434d65fa0891a961504c8882893fad7609c6 (patch)
treefed6238e9b47fac3869b4443a362b0e217e468a9 /compiler/GHC/HsToCore
parent3486ebe6f960cc55d52c1e645ee15fdeb277d0ab (diff)
downloadhaskell-37f0434d65fa0891a961504c8882893fad7609c6.tar.gz
Constant-folding: don't pass through GHC's Int/Word (fix #11704)
Constant-folding rules for integerToWord/integerToInt were performing the following coercions at compilation time: integerToWord: target's Integer -> ghc's Word -> target's Word integerToInt : target's Integer -> ghc's Int -> target's Int 1) It was wrong for cross-compilers when GHC's word size is smaller than the target one. This patch avoids passing through GHC's word-sized types: integerToWord: target's Integer -> ghc's Integer -> target's Word integerToInt : target's Integer -> ghc's Integer -> target's Int 2) Additionally we didn't wrap the target word/int literal to make it fit into the target's range! This broke the invariant of literals only containing values in range. The existing code is wrong only with a 64-bit cross-compiling GHC, targeting a 32-bit platform, and performing constant folding on a literal that doesn't fit in a 32-bit word. If GHC was built with DEBUG, the assertion in GHC.Types.Literal.mkLitWord would fail. Otherwise the bad transformation would go unnoticed.
Diffstat (limited to 'compiler/GHC/HsToCore')
-rw-r--r--compiler/GHC/HsToCore/Foreign/Decl.hs2
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/GHC/HsToCore/Foreign/Decl.hs b/compiler/GHC/HsToCore/Foreign/Decl.hs
index 4d6abc4132..e50db56eec 100644
--- a/compiler/GHC/HsToCore/Foreign/Decl.hs
+++ b/compiler/GHC/HsToCore/Foreign/Decl.hs
@@ -453,7 +453,7 @@ dsFExportDynamic id co0 cconv = do
to be entered using an external calling convention
(stdcall, ccall).
-}
- adj_args = [ mkIntLitInt platform (ccallConvToInt cconv)
+ adj_args = [ mkIntLit platform (fromIntegral (ccallConvToInt cconv))
, Var stbl_value
, Lit (LitLabel fe_nm mb_sz_args IsFunction)
, Lit (mkLitString typestring)