From 877780beb55fd59e01217da0d87ca4067e4c8f67 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 8 Jun 2019 21:29:24 +0200 Subject: [PATCH] Fix ReduceNestingTransform bug introduced in commit 7f27768ff96c6 --- .../IL/Transforms/ReduceNestingTransform.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs index a259febdd..03e3297f3 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs @@ -238,7 +238,6 @@ namespace ICSharpCode.Decompiler.IL if (defaultTree.Count > 1 && !(parentBlock.Parent is BlockContainer)) return false; - EnsureEndPointUnreachable(parentBlock, exitInst); context.Step("Extract default case of switch", switchContainer); // replace all break; statements with the exitInst @@ -255,8 +254,13 @@ namespace ICSharpCode.Decompiler.IL switchContainer.Blocks.Remove(block); // replace the parent block exit with the default case instructions - Debug.Assert(parentBlock.Instructions.Last() == exitInst); - parentBlock.Instructions.RemoveLast(); + if (parentBlock.Instructions.Last() == exitInst) { + parentBlock.Instructions.RemoveLast(); + } + // Note: even though we don't check that the switchContainer is near the end of the block, + // we know this must be the case because we know "exitInst" is a leave/branch and directly + // follows the switchContainer. + Debug.Assert(parentBlock.Instructions.Last() == switchContainer); parentBlock.Instructions.AddRange(defaultBlock.Instructions); // add any additional blocks from the default case to the parent container