Browse Source

Support extraction out of control-flow IfInstruction even if it isn't using a Block as TrueInst/FalseInst.

pull/2069/head
Daniel Grunwald 5 years ago
parent
commit
12094a8376
  1. 3
      ICSharpCode.Decompiler/IL/Transforms/FixLoneIsInst.cs
  2. 8
      ICSharpCode.Decompiler/IL/Transforms/ILExtraction.cs

3
ICSharpCode.Decompiler/IL/Transforms/FixLoneIsInst.cs

@ -46,6 +46,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (isInst.Parent.MatchCompEqualsNull(out _) || isInst.Parent.MatchCompNotEqualsNull(out _)) {
continue; // supported pattern "expr is T"
}
if (isInst.Parent is Block { Kind: BlockKind.ControlFlow }) {
continue; // supported via StatementBuilder.VisitIsInst
}
instructionsToFix.Add(isInst);
}
// Need to delay fixing until we're done with iteration, because Extract() modifies parents

8
ICSharpCode.Decompiler/IL/Transforms/ILExtraction.cs

@ -97,6 +97,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms
ctx.FlagsBeingMoved = instToExtract.Flags;
ILInstruction inst = instToExtract;
while (inst != null) {
if (inst.Parent is IfInstruction ifInst && inst.SlotInfo != IfInstruction.ConditionSlot) {
// this context doesn't support extraction, but maybe we can create a block here?
if (ifInst.ResultType == StackType.Void) {
Block newBlock = new Block();
inst.ReplaceWith(newBlock);
newBlock.Instructions.Add(inst);
}
}
if (inst.Parent is Block block && block.Kind == BlockKind.ControlFlow) {
// We've reached the target block, and extraction is possible all the way.
int insertIndex = inst.ChildIndex;

Loading…
Cancel
Save