From abd9af29c61fe1910eb49915e4ec37575a230a26 Mon Sep 17 00:00:00 2001 From: Chicken-Bones Date: Tue, 9 Jun 2020 20:28:53 +1000 Subject: [PATCH] Fix failed assertion when encountering a finally block with an unreachable endpoint in ReduceNestingTransform. --- .../IL/Transforms/ReduceNestingTransform.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs index d8c7f6de8..7e2dd7dc7 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs @@ -364,13 +364,18 @@ namespace ICSharpCode.Decompiler.IL ILInstruction leavingInst = leave.TargetContainer; Debug.Assert(!leavingInst.HasFlag(InstructionFlags.EndPointUnreachable)); while (!(leavingInst.Parent is Block b) || leavingInst == b.Instructions.Last()) { - // cannot duplicate leaves from finally containers - if (leavingInst.Parent is TryFinally tryFinally && leavingInst.SlotInfo == TryFinally.FinallyBlockSlot) { - Debug.Assert(leave.TargetContainer == tryFinally.FinallyBlock); //finally cannot have control flow - return false; - } - leavingInst = leavingInst.Parent; + + if (leavingInst is TryFinally tryFinally) { + if (leavingInst.SlotInfo == TryFinally.FinallyBlockSlot) { // cannot duplicate leaves from finally containers + Debug.Assert(leave.TargetContainer == tryFinally.FinallyBlock); //finally cannot have control flow + return false; + } + if (leavingInst.HasFlag(InstructionFlags.EndPointUnreachable)) { // finally block changes return value/throws an exception? Yikes. Lets leave it alone + Debug.Assert(tryFinally.FinallyBlock.HasFlag(InstructionFlags.EndPointUnreachable)); + return false; + } + } Debug.Assert(!leavingInst.HasFlag(InstructionFlags.EndPointUnreachable)); Debug.Assert(!(leavingInst is ILFunction)); }