From b3370506ae972d4f3270011b71e4daca11a8f539 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 5 Nov 2017 18:28:41 +0100 Subject: [PATCH] Fix small regressions --- ICSharpCode.Decompiler/CSharp/StatementBuilder.cs | 15 +++++++++------ .../IL/Transforms/HighLevelLoopTransform.cs | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index b6bb3bf99..9af72d60b 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -695,6 +695,9 @@ namespace ICSharpCode.Decompiler.CSharp // Remove the entrypoint label if all jumps to the label were replaced with 'continue;' statements blockStatement.Statements.First().Remove(); } + + if (blockStatement.LastOrDefault() is ContinueStatement continueStmt) + continueStmt.Remove(); return new WhileStatement(new PrimitiveExpression(true), blockStatement); case ContainerKind.While: continueTarget = container.EntryPoint; @@ -714,8 +717,8 @@ namespace ICSharpCode.Decompiler.CSharp blockStatement.Add(new LabelStatement { Label = container.EntryPoint.Label }); } - if (blockStatement.LastOrDefault() is ContinueStatement stmt) - stmt.Remove(); + if (blockStatement.LastOrDefault() is ContinueStatement continueStmt2) + continueStmt2.Remove(); return new WhileStatement(exprBuilder.TranslateCondition(condition), blockStatement); case ContainerKind.DoWhile: continueTarget = container.Blocks.Last(); @@ -726,8 +729,8 @@ namespace ICSharpCode.Decompiler.CSharp // Remove the entrypoint label if all jumps to the label were replaced with 'continue;' statements blockStatement.Statements.First().Remove(); } - if (blockStatement.LastOrDefault() is ContinueStatement continueStmt) - continueStmt.Remove(); + if (blockStatement.LastOrDefault() is ContinueStatement continueStmt3) + continueStmt3.Remove(); return new DoWhileStatement { EmbeddedStatement = blockStatement, Condition = exprBuilder.TranslateCondition(condition) @@ -746,8 +749,8 @@ namespace ICSharpCode.Decompiler.CSharp Condition = exprBuilder.TranslateCondition(condition), EmbeddedStatement = blockStatement }; - if (blockStatement.LastOrDefault() is ContinueStatement continueStmt2) - continueStmt2.Remove(); + if (blockStatement.LastOrDefault() is ContinueStatement continueStmt4) + continueStmt4.Remove(); for (int i = 0; i < continueTarget.Instructions.Count - 1; i++) { forStmt.Iterators.Add(Convert(continueTarget.Instructions[i])); } diff --git a/ICSharpCode.Decompiler/IL/Transforms/HighLevelLoopTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/HighLevelLoopTransform.cs index 0931887b4..3a275e3e7 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/HighLevelLoopTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/HighLevelLoopTransform.cs @@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; var last = loop.EntryPoint.Instructions.Last(); var ifInstruction = loop.EntryPoint.Instructions.SecondToLastOrDefault() as IfInstruction; - if (!ifInstruction.FalseInst.MatchNop()) + if (ifInstruction == null || !ifInstruction.FalseInst.MatchNop()) return false; bool swapBranches = false; ILInstruction condition = ifInstruction.Condition;