summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2015-04-05 22:50:42 +0200
committerJoachim Breitner <mail@joachim-breitner.de>2015-04-05 22:52:48 +0200
commita838d1f7c668f6c5886ce350cb456f3ecbcb1499 (patch)
tree7c7a9216a7a03f187eceeda2a5ffeb7aaf7eaea2
parenta1404e88e8254eadd542c31796ab469a9f79a876 (diff)
downloadhaskell-a838d1f7c668f6c5886ce350cb456f3ecbcb1499.tar.gz
CmmSwitch: Do not trip over a case with no (valid) branches
This fixes #10245. I did not commit the test case, as it fails unconditionally with a compiler built with -DDEBUG, so maybe it is bogus Haskell anyways.
-rw-r--r--compiler/cmm/CmmSwitch.hs6
1 files changed, 4 insertions, 2 deletions
diff --git a/compiler/cmm/CmmSwitch.hs b/compiler/cmm/CmmSwitch.hs
index 95e57c70af..09abec6f8b 100644
--- a/compiler/cmm/CmmSwitch.hs
+++ b/compiler/cmm/CmmSwitch.hs
@@ -88,7 +88,8 @@ minJumpTableOffset = 2
-- We use an Integer for the keys the map so that it can be used in switches on
-- unsigned as well as signed integers.
--
--- The map must not be empty.
+-- The map may be empty (we prune out-of-range branches here, so it could be us
+-- emptying it).
--
-- Before code generation, the table needs to be brought into a form where all
-- entries are non-negative, so that it can be compiled into a jump table.
@@ -270,6 +271,7 @@ createSwitchPlan (SwitchTargets signed mbdef range m) =
--- Step 1: Splitting at large holes
---
splitAtHoles :: Integer -> M.Map Integer a -> [M.Map Integer a]
+splitAtHoles _ m | M.null m = []
splitAtHoles holeSize m = map (\range -> restrictMap range m) nonHoles
where
holes = filter (\(l,h) -> h - l > holeSize) $ zip (M.keys m) (tail (M.keys m))
@@ -282,7 +284,7 @@ splitAtHoles holeSize m = map (\range -> restrictMap range m) nonHoles
--- Step 2: Avoid small jump tables
---
-- We do not want jump tables below a certain size. This breaks them up
--- (into singleton maps, for now)
+-- (into singleton maps, for now).
breakTooSmall :: M.Map Integer a -> [M.Map Integer a]
breakTooSmall m
| M.size m > minJumpTableSize = [m]