diff --git a/ICSharpCode.Decompiler/IL/Transforms/FixLoneIsInst.cs b/ICSharpCode.Decompiler/IL/Transforms/FixLoneIsInst.cs index 1f6b9856c..3b270f62b 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/FixLoneIsInst.cs +++ b/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 diff --git a/ICSharpCode.Decompiler/IL/Transforms/ILExtraction.cs b/ICSharpCode.Decompiler/IL/Transforms/ILExtraction.cs index 84878611f..644c43a7f 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ILExtraction.cs +++ b/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;