summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-10-13 19:20:28 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-10-15 21:58:27 -0400
commitcc536288c32df9c4b9f37020b76348f58a57b3cb (patch)
treee3072e960fb0a29163decf4554471274790c99c1
parentae146b536445d20ef9983ff0e38ce1beaec6f321 (diff)
downloadhaskell-cc536288c32df9c4b9f37020b76348f58a57b3cb.tar.gz
compiler/ByteCode: Allow 2^32 local labels
This widens LocalLabel to 2^16, avoiding the crash observed in #14334. Closes #14334.
-rw-r--r--compiler/GHC/ByteCode/Asm.hs4
-rw-r--r--compiler/GHC/ByteCode/Instr.hs3
-rw-r--r--compiler/GHC/CoreToByteCode.hs4
3 files changed, 7 insertions, 4 deletions
diff --git a/compiler/GHC/ByteCode/Asm.hs b/compiler/GHC/ByteCode/Asm.hs
index b59748bc92..c344823ccb 100644
--- a/compiler/GHC/ByteCode/Asm.hs
+++ b/compiler/GHC/ByteCode/Asm.hs
@@ -179,7 +179,9 @@ assembleBCO platform (ProtoBCO { protoBCOName = nm
-- this BCO to be long.
(n_insns0, lbl_map0) = inspectAsm platform False initial_offset asm
((n_insns, lbl_map), long_jumps)
- | isLarge n_insns0 = (inspectAsm platform True initial_offset asm, True)
+ | isLarge (fromIntegral $ Map.size lbl_map0)
+ || isLarge n_insns0
+ = (inspectAsm platform True initial_offset asm, True)
| otherwise = ((n_insns0, lbl_map0), False)
env :: LocalLabel -> Word
diff --git a/compiler/GHC/ByteCode/Instr.hs b/compiler/GHC/ByteCode/Instr.hs
index aecc7c9181..bc9b114573 100644
--- a/compiler/GHC/ByteCode/Instr.hs
+++ b/compiler/GHC/ByteCode/Instr.hs
@@ -50,7 +50,8 @@ data ProtoBCO a
protoBCOFFIs :: [FFIInfo]
}
-newtype LocalLabel = LocalLabel { getLocalLabel :: Word16 }
+-- | A local block label (e.g. identifying a case alternative).
+newtype LocalLabel = LocalLabel { getLocalLabel :: Word32 }
deriving (Eq, Ord)
instance Outputable LocalLabel where
diff --git a/compiler/GHC/CoreToByteCode.hs b/compiler/GHC/CoreToByteCode.hs
index 25503fa7c3..8043ccaef9 100644
--- a/compiler/GHC/CoreToByteCode.hs
+++ b/compiler/GHC/CoreToByteCode.hs
@@ -1968,7 +1968,7 @@ data BcM_State
{ bcm_hsc_env :: HscEnv
, uniqSupply :: UniqSupply -- for generating fresh variable names
, thisModule :: Module -- current module (for breakpoints)
- , nextlabel :: Word16 -- for generating local labels
+ , nextlabel :: Word32 -- for generating local labels
, ffis :: [FFIInfo] -- ffi info blocks, to free later
-- Should be free()d when it is GCd
, modBreaks :: Maybe ModBreaks -- info about breakpoints
@@ -2040,7 +2040,7 @@ getLabelBc
panic "getLabelBc: Ran out of labels"
return (st{nextlabel = nl + 1}, LocalLabel nl)
-getLabelsBc :: Word16 -> BcM [LocalLabel]
+getLabelsBc :: Word32 -> BcM [LocalLabel]
getLabelsBc n
= BcM $ \st -> let ctr = nextlabel st
in return (st{nextlabel = ctr+n}, coerce [ctr .. ctr+n-1])