diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs index da2685955..4f79d5850 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs @@ -79,6 +79,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness Console.WriteLine(NoForeachDueToMultipleCurrentAccess(new List { 1, 2, 3, 4, 5 })); Console.WriteLine(NoForeachCallWithSideEffect(new CustomClassEnumeratorWithIDisposable())); LoopWithGotoRepeat(); + Console.WriteLine("LoopFollowedByIf: {0}", LoopFollowedByIf()); } public static void ForWithMultipleVariables() @@ -246,5 +247,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness } Console.WriteLine("after finally"); } + + private static int LoopFollowedByIf() + { + int num = 0; + while (num == 0) { + num++; + } + if (num == 0) { + return -1; + } + return num; + } } } diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs index c9fc8ee2a..cee558bc4 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs @@ -4,7 +4,7 @@ { public void Test(bool arg) { - switch (arg) { + if (!arg && arg) { } } diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs index ab264e3da..cb50ec78f 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs @@ -116,6 +116,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow if (!(tailOnly || block.Instructions.Count == 2)) return false; trueValues = trueValues.IntersectWith(inputValues); + if (trueValues.SetEquals(inputValues) || trueValues.IsEmpty) + return false; Block trueBlock; if (trueInst.MatchBranch(out trueBlock) && AnalyzeBlock(trueBlock, trueValues)) { // OK, true block was further analyzed.