Browse Source

Fix failed assertion when encountering a finally block with an unreachable endpoint in ReduceNestingTransform.

pull/1880/head
Chicken-Bones 5 years ago
parent
commit
abd9af29c6
  1. 13
      ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs

13
ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs

@ -364,13 +364,18 @@ namespace ICSharpCode.Decompiler.IL
ILInstruction leavingInst = leave.TargetContainer; ILInstruction leavingInst = leave.TargetContainer;
Debug.Assert(!leavingInst.HasFlag(InstructionFlags.EndPointUnreachable)); Debug.Assert(!leavingInst.HasFlag(InstructionFlags.EndPointUnreachable));
while (!(leavingInst.Parent is Block b) || leavingInst == b.Instructions.Last()) { while (!(leavingInst.Parent is Block b) || leavingInst == b.Instructions.Last()) {
// cannot duplicate leaves from finally containers leavingInst = leavingInst.Parent;
if (leavingInst.Parent is TryFinally tryFinally && leavingInst.SlotInfo == TryFinally.FinallyBlockSlot) {
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 Debug.Assert(leave.TargetContainer == tryFinally.FinallyBlock); //finally cannot have control flow
return false; return false;
} }
if (leavingInst.HasFlag(InstructionFlags.EndPointUnreachable)) { // finally block changes return value/throws an exception? Yikes. Lets leave it alone
leavingInst = leavingInst.Parent; Debug.Assert(tryFinally.FinallyBlock.HasFlag(InstructionFlags.EndPointUnreachable));
return false;
}
}
Debug.Assert(!leavingInst.HasFlag(InstructionFlags.EndPointUnreachable)); Debug.Assert(!leavingInst.HasFlag(InstructionFlags.EndPointUnreachable));
Debug.Assert(!(leavingInst is ILFunction)); Debug.Assert(!(leavingInst is ILFunction));
} }

Loading…
Cancel
Save