From 696fdca9231c2cca442457eb73e52f6214de1597 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 11 Jul 2020 23:02:15 +0200 Subject: [PATCH] Always create a block when inverting an if. This keeps the ILAst more uniform and ensures extraction is possible for the code in the then statement. --- .../IL/ControlFlow/ConditionDetection.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs index 86de21751..a27a9f6bb 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs @@ -362,16 +362,11 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow //save a copy var thenInst = ifInst.TrueInst; - if (ifInst != block.Instructions.SecondToLastOrDefault()) { - // extract "else...; exit". - // Note that this will only extract instructions that were previously inlined from another block - // (via InlineExitBranch), so the instructions are already fully-transformed. - // So it's OK to move them into a nested block again (which hides them from the following block transforms). - ifInst.TrueInst = ExtractBlock(block, block.Instructions.IndexOf(ifInst) + 1, block.Instructions.Count); - } else { - block.Instructions.RemoveAt(block.Instructions.Count - 1); - ifInst.TrueInst = exitInst; - } + // extract "else...; exit". + // Note that this will only extract instructions that were previously inlined from another block + // (via InlineExitBranch), so the instructions are already fully-transformed. + // So it's OK to move them into a nested block again (which hides them from the following block transforms). + ifInst.TrueInst = ExtractBlock(block, block.Instructions.IndexOf(ifInst) + 1, block.Instructions.Count); if (thenInst is Block thenBlock) { block.Instructions.AddRange(thenBlock.Instructions);