Skip to content

Commit da905ac

Browse files
committed
Fix logic error in last commit, and ignore fault clauses in ReduceNestingTransform
1 parent abd9af2 commit da905ac

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -364,18 +364,22 @@ private bool CanDuplicateExit(ILInstruction exit, Block continueTarget, out ILIn
364364
ILInstruction leavingInst = leave.TargetContainer;
365365
Debug.Assert(!leavingInst.HasFlag(InstructionFlags.EndPointUnreachable));
366366
while (!(leavingInst.Parent is Block b) || leavingInst == b.Instructions.Last()) {
367-
leavingInst = leavingInst.Parent;
368-
369-
if (leavingInst is TryFinally tryFinally) {
367+
if (leavingInst.Parent is TryFinally tryFinally) {
370368
if (leavingInst.SlotInfo == TryFinally.FinallyBlockSlot) { // cannot duplicate leaves from finally containers
371369
Debug.Assert(leave.TargetContainer == tryFinally.FinallyBlock); //finally cannot have control flow
372370
return false;
373371
}
374-
if (leavingInst.HasFlag(InstructionFlags.EndPointUnreachable)) { // finally block changes return value/throws an exception? Yikes. Lets leave it alone
372+
if (tryFinally.HasFlag(InstructionFlags.EndPointUnreachable)) { // finally block changes return value/throws an exception? Yikes. Lets leave it alone
375373
Debug.Assert(tryFinally.FinallyBlock.HasFlag(InstructionFlags.EndPointUnreachable));
376374
return false;
377375
}
378376
}
377+
else if (leavingInst.Parent is TryFault tryFault && leavingInst.SlotInfo == TryFault.FaultBlockSlot) { // cannot duplicate leaves from fault containers either
378+
Debug.Assert(leave.TargetContainer == tryFault.FaultBlock);
379+
return false;
380+
}
381+
382+
leavingInst = leavingInst.Parent;
379383
Debug.Assert(!leavingInst.HasFlag(InstructionFlags.EndPointUnreachable));
380384
Debug.Assert(!(leavingInst is ILFunction));
381385
}

0 commit comments

Comments
 (0)