[commit: ghc] master: CmmSwitch: Do not trip over a case with no (valid) branches (a838d1f)
git at git.haskell.org
git at git.haskell.org
Sun Apr 5 20:53:07 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/a838d1f7c668f6c5886ce350cb456f3ecbcb1499/ghc
>---------------------------------------------------------------
commit a838d1f7c668f6c5886ce350cb456f3ecbcb1499
Author: Joachim Breitner <mail at joachim-breitner.de>
Date: Sun Apr 5 22:50:42 2015 +0200
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.
>---------------------------------------------------------------
a838d1f7c668f6c5886ce350cb456f3ecbcb1499
compiler/cmm/CmmSwitch.hs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/compiler/cmm/CmmSwitch.hs b/compiler/cmm/CmmSwitch.hs
index 95e57c7..09abec6 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]
More information about the ghc-commits
mailing list