Browse Source

Fix #1392: LoopDetection should take switch block containers into account in IncludeNestedContainers.

pull/1440/head
Siegfried Pammer 7 years ago
parent
commit
29527b804e
  1. 18
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/Loops.cs
  2. 2
      ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs

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

@ -259,5 +259,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
return num;
}
static void Issue1392ForWithNestedSwitchPlusGoto()
{
for (int i = 0; i < 100; i++) {
again:
switch (i) {
case 10:
Console.WriteLine("10");
break;
case 25:
Console.WriteLine("25");
break;
case 50:
Console.WriteLine("50");
goto again;
}
}
}
}
}

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

@ -142,7 +142,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
void IncludeBlock(Block block)
{
if (block.Instructions[0] is BlockContainer nestedContainer) {
foreach (var nestedContainer in block.Instructions.OfType<BlockContainer>()) {
// Just in case the block has multiple nested containers (e.g. due to loop and switch),
// also check the entry point:
IncludeBlock(nestedContainer.EntryPoint);

Loading…
Cancel
Save