Browse Source

Merge pull request #1295 from Chicken-Bones/switchdetection

Abort SwitchAnalysis on duplicate condition (redundant code)
pull/1317/head
Daniel Grunwald 7 years ago committed by GitHub
parent
commit
382a78849a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs
  2. 2
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs
  3. 2
      ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs

13
ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs

@ -79,6 +79,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine(NoForeachDueToMultipleCurrentAccess(new List<int> { 1, 2, 3, 4, 5 })); Console.WriteLine(NoForeachDueToMultipleCurrentAccess(new List<int> { 1, 2, 3, 4, 5 }));
Console.WriteLine(NoForeachCallWithSideEffect(new CustomClassEnumeratorWithIDisposable<int>())); Console.WriteLine(NoForeachCallWithSideEffect(new CustomClassEnumeratorWithIDisposable<int>()));
LoopWithGotoRepeat(); LoopWithGotoRepeat();
Console.WriteLine("LoopFollowedByIf: {0}", LoopFollowedByIf());
} }
public static void ForWithMultipleVariables() public static void ForWithMultipleVariables()
@ -246,5 +247,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
} }
Console.WriteLine("after finally"); Console.WriteLine("after finally");
} }
private static int LoopFollowedByIf()
{
int num = 0;
while (num == 0) {
num++;
}
if (num == 0) {
return -1;
}
return num;
}
} }
} }

2
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue959.cs

@ -4,7 +4,7 @@
{ {
public void Test(bool arg) public void Test(bool arg)
{ {
switch (arg) { if (!arg && arg) {
} }
} }

2
ICSharpCode.Decompiler/IL/ControlFlow/SwitchAnalysis.cs

@ -116,6 +116,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
if (!(tailOnly || block.Instructions.Count == 2)) if (!(tailOnly || block.Instructions.Count == 2))
return false; return false;
trueValues = trueValues.IntersectWith(inputValues); trueValues = trueValues.IntersectWith(inputValues);
if (trueValues.SetEquals(inputValues) || trueValues.IsEmpty)
return false;
Block trueBlock; Block trueBlock;
if (trueInst.MatchBranch(out trueBlock) && AnalyzeBlock(trueBlock, trueValues)) { if (trueInst.MatchBranch(out trueBlock) && AnalyzeBlock(trueBlock, trueValues)) {
// OK, true block was further analyzed. // OK, true block was further analyzed.

Loading…
Cancel
Save