Browse Source

Fix #1395: do-while loop missing entry-point label.

pull/1409/head
Siegfried Pammer 7 years ago
parent
commit
deeb603fd7
  1. 49
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs
  2. 121
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il
  3. 92
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.mcs.il
  4. 88
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il
  5. 92
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.mcs.il
  6. 85
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il
  7. 122
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il
  8. 10
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  9. 8
      ICSharpCode.Decompiler/IL/Transforms/HighLevelLoopTransform.cs

49
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs

@ -715,6 +715,55 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -715,6 +715,55 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine("End of method");
}
public void Issue1395(int count)
{
Environment.GetCommandLineArgs();
for (int i = 0; i < count; i++) {
Environment.GetCommandLineArgs();
do {
#if OPT || MCS
IL_0013:
#else
IL_0016:
#endif
Environment.GetCommandLineArgs();
if (Condition("part1")) {
Environment.GetEnvironmentVariables();
if (Condition("restart")) {
#if OPT || MCS
goto IL_0013;
#else
goto IL_0016;
#endif
}
} else {
Environment.GetLogicalDrives();
}
Environment.GetCommandLineArgs();
while (count > 0) {
switch (count) {
case 0:
case 1:
case 2:
Environment.GetCommandLineArgs();
break;
case 3:
case 5:
case 6:
Environment.GetEnvironmentVariables();
break;
default:
Environment.GetLogicalDrives();
break;
}
}
count++;
} while (Condition("do-while"));
Environment.GetCommandLineArgs();
}
Environment.GetCommandLineArgs();
}
public void ForLoop()
{
Console.WriteLine("Initial");

121
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.il

@ -2681,6 +2681,127 @@ @@ -2681,6 +2681,127 @@
IL_0098: ret
} // end of method Loops::DoWhileLoop
.method public hidebysig instance void
Issue1395(int32 count) cil managed
{
// Code size 218 (0xda)
.maxstack 2
.locals init (int32 V_0,
bool V_1,
int32 V_2)
IL_0000: nop
IL_0001: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0006: pop
IL_0007: ldc.i4.0
IL_0008: stloc.0
IL_0009: br IL_00c8
IL_000e: nop
IL_000f: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0014: pop
IL_0015: nop
IL_0016: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_001b: pop
IL_001c: ldarg.0
IL_001d: ldstr "part1"
IL_0022: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0027: ldc.i4.0
IL_0028: ceq
IL_002a: stloc.1
IL_002b: ldloc.1
IL_002c: brtrue.s IL_004d
IL_002e: nop
IL_002f: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_0034: pop
IL_0035: ldarg.0
IL_0036: ldstr "restart"
IL_003b: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0040: ldc.i4.0
IL_0041: ceq
IL_0043: stloc.1
IL_0044: ldloc.1
IL_0045: brtrue.s IL_004a
IL_0047: nop
IL_0048: br.s IL_0016
IL_004a: nop
IL_004b: br.s IL_0055
IL_004d: nop
IL_004e: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_0053: pop
IL_0054: nop
IL_0055: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_005a: pop
IL_005b: br.s IL_009d
IL_005d: nop
IL_005e: ldarg.1
IL_005f: stloc.2
IL_0060: ldloc.2
IL_0061: switch (
IL_0084,
IL_0084,
IL_0084,
IL_008c,
IL_0094,
IL_008c,
IL_008c)
IL_0082: br.s IL_0094
IL_0084: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0089: pop
IL_008a: br.s IL_009c
IL_008c: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_0091: pop
IL_0092: br.s IL_009c
IL_0094: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_0099: pop
IL_009a: br.s IL_009c
IL_009c: nop
IL_009d: ldarg.1
IL_009e: ldc.i4.0
IL_009f: cgt
IL_00a1: stloc.1
IL_00a2: ldloc.1
IL_00a3: brtrue.s IL_005d
IL_00a5: ldarg.1
IL_00a6: ldc.i4.1
IL_00a7: add
IL_00a8: starg.s count
IL_00aa: nop
IL_00ab: ldarg.0
IL_00ac: ldstr "do-while"
IL_00b1: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_00b6: stloc.1
IL_00b7: ldloc.1
IL_00b8: brtrue IL_0015
IL_00bd: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00c2: pop
IL_00c3: nop
IL_00c4: ldloc.0
IL_00c5: ldc.i4.1
IL_00c6: add
IL_00c7: stloc.0
IL_00c8: ldloc.0
IL_00c9: ldarg.1
IL_00ca: clt
IL_00cc: stloc.1
IL_00cd: ldloc.1
IL_00ce: brtrue IL_000e
IL_00d3: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00d8: pop
IL_00d9: ret
} // end of method Loops::Issue1395
.method public hidebysig instance void
ForLoop() cil managed
{

92
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.mcs.il

@ -1904,6 +1904,98 @@ @@ -1904,6 +1904,98 @@
IL_008c: ret
} // end of method Loops::DoWhileLoop
.method public hidebysig instance void
Issue1395(int32 count) cil managed
{
// Code size 216 (0xd8)
.maxstack 19
.locals init (int32 V_0,
int32 V_1)
IL_0000: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0005: pop
IL_0006: ldc.i4.0
IL_0007: stloc.0
IL_0008: br IL_00ca
IL_000d: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0012: pop
IL_0013: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0018: pop
IL_0019: ldarg.0
IL_001a: ldstr "part1"
IL_001f: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0024: brfalse IL_0049
IL_0029: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_002e: pop
IL_002f: ldarg.0
IL_0030: ldstr "restart"
IL_0035: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_003a: brfalse IL_0044
IL_003f: br IL_0013
IL_0044: br IL_004f
IL_0049: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_004e: pop
IL_004f: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0054: pop
IL_0055: br IL_00a4
IL_005a: ldarg.1
IL_005b: stloc.1
IL_005c: ldloc.1
IL_005d: switch (
IL_0083,
IL_0083,
IL_0083,
IL_008e,
IL_0099,
IL_008e,
IL_008e)
IL_007e: br IL_0099
IL_0083: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0088: pop
IL_0089: br IL_00a4
IL_008e: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_0093: pop
IL_0094: br IL_00a4
IL_0099: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_009e: pop
IL_009f: br IL_00a4
IL_00a4: ldarg.1
IL_00a5: ldc.i4.0
IL_00a6: bgt IL_005a
IL_00ab: ldarg.1
IL_00ac: ldc.i4.1
IL_00ad: add
IL_00ae: starg.s count
IL_00b0: ldarg.0
IL_00b1: ldstr "do-while"
IL_00b6: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_00bb: brtrue IL_0013
IL_00c0: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00c5: pop
IL_00c6: ldloc.0
IL_00c7: ldc.i4.1
IL_00c8: add
IL_00c9: stloc.0
IL_00ca: ldloc.0
IL_00cb: ldarg.1
IL_00cc: blt IL_000d
IL_00d1: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00d6: pop
IL_00d7: ret
} // end of method Loops::Issue1395
.method public hidebysig instance void
ForLoop() cil managed
{

88
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.il

@ -2067,6 +2067,94 @@ @@ -2067,6 +2067,94 @@
IL_0073: ret
} // end of method Loops::DoWhileLoop
.method public hidebysig instance void
Issue1395(int32 count) cil managed
{
// Code size 182 (0xb6)
.maxstack 2
.locals init (int32 V_0,
int32 V_1)
IL_0000: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0005: pop
IL_0006: ldc.i4.0
IL_0007: stloc.0
IL_0008: br IL_00a8
IL_000d: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0012: pop
IL_0013: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0018: pop
IL_0019: ldarg.0
IL_001a: ldstr "part1"
IL_001f: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0024: brfalse.s IL_003b
IL_0026: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_002b: pop
IL_002c: ldarg.0
IL_002d: ldstr "restart"
IL_0032: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0037: brfalse.s IL_0041
IL_0039: br.s IL_0013
IL_003b: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_0040: pop
IL_0041: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0046: pop
IL_0047: br.s IL_0085
IL_0049: ldarg.1
IL_004a: stloc.1
IL_004b: ldloc.1
IL_004c: switch (
IL_006f,
IL_006f,
IL_006f,
IL_0077,
IL_007f,
IL_0077,
IL_0077)
IL_006d: br.s IL_007f
IL_006f: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0074: pop
IL_0075: br.s IL_0085
IL_0077: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_007c: pop
IL_007d: br.s IL_0085
IL_007f: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_0084: pop
IL_0085: ldarg.1
IL_0086: ldc.i4.0
IL_0087: bgt.s IL_0049
IL_0089: ldarg.1
IL_008a: ldc.i4.1
IL_008b: add
IL_008c: starg.s count
IL_008e: ldarg.0
IL_008f: ldstr "do-while"
IL_0094: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0099: brtrue IL_0013
IL_009e: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00a3: pop
IL_00a4: ldloc.0
IL_00a5: ldc.i4.1
IL_00a6: add
IL_00a7: stloc.0
IL_00a8: ldloc.0
IL_00a9: ldarg.1
IL_00aa: blt IL_000d
IL_00af: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00b4: pop
IL_00b5: ret
} // end of method Loops::Issue1395
.method public hidebysig instance void
ForLoop() cil managed
{

92
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.mcs.il

@ -1904,6 +1904,98 @@ @@ -1904,6 +1904,98 @@
IL_008c: ret
} // end of method Loops::DoWhileLoop
.method public hidebysig instance void
Issue1395(int32 count) cil managed
{
// Code size 216 (0xd8)
.maxstack 19
.locals init (int32 V_0,
int32 V_1)
IL_0000: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0005: pop
IL_0006: ldc.i4.0
IL_0007: stloc.0
IL_0008: br IL_00ca
IL_000d: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0012: pop
IL_0013: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0018: pop
IL_0019: ldarg.0
IL_001a: ldstr "part1"
IL_001f: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0024: brfalse IL_0049
IL_0029: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_002e: pop
IL_002f: ldarg.0
IL_0030: ldstr "restart"
IL_0035: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_003a: brfalse IL_0044
IL_003f: br IL_0013
IL_0044: br IL_004f
IL_0049: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_004e: pop
IL_004f: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0054: pop
IL_0055: br IL_00a4
IL_005a: ldarg.1
IL_005b: stloc.1
IL_005c: ldloc.1
IL_005d: switch (
IL_0083,
IL_0083,
IL_0083,
IL_008e,
IL_0099,
IL_008e,
IL_008e)
IL_007e: br IL_0099
IL_0083: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0088: pop
IL_0089: br IL_00a4
IL_008e: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_0093: pop
IL_0094: br IL_00a4
IL_0099: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_009e: pop
IL_009f: br IL_00a4
IL_00a4: ldarg.1
IL_00a5: ldc.i4.0
IL_00a6: bgt IL_005a
IL_00ab: ldarg.1
IL_00ac: ldc.i4.1
IL_00ad: add
IL_00ae: starg.s count
IL_00b0: ldarg.0
IL_00b1: ldstr "do-while"
IL_00b6: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_00bb: brtrue IL_0013
IL_00c0: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00c5: pop
IL_00c6: ldloc.0
IL_00c7: ldc.i4.1
IL_00c8: add
IL_00c9: stloc.0
IL_00ca: ldloc.0
IL_00cb: ldarg.1
IL_00cc: blt IL_000d
IL_00d1: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00d6: pop
IL_00d7: ret
} // end of method Loops::Issue1395
.method public hidebysig instance void
ForLoop() cil managed
{

85
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.opt.roslyn.il

@ -2011,6 +2011,91 @@ @@ -2011,6 +2011,91 @@
IL_0073: ret
} // end of method Loops::DoWhileLoop
.method public hidebysig instance void
Issue1395(int32 count) cil managed
{
// Code size 180 (0xb4)
.maxstack 2
.locals init (int32 V_0)
IL_0000: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0005: pop
IL_0006: ldc.i4.0
IL_0007: stloc.0
IL_0008: br IL_00a6
IL_000d: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0012: pop
IL_0013: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0018: pop
IL_0019: ldarg.0
IL_001a: ldstr "part1"
IL_001f: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0024: brfalse.s IL_003b
IL_0026: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_002b: pop
IL_002c: ldarg.0
IL_002d: ldstr "restart"
IL_0032: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0037: brfalse.s IL_0041
IL_0039: br.s IL_0013
IL_003b: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_0040: pop
IL_0041: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0046: pop
IL_0047: br.s IL_0083
IL_0049: ldarg.1
IL_004a: switch (
IL_006d,
IL_006d,
IL_006d,
IL_0075,
IL_007d,
IL_0075,
IL_0075)
IL_006b: br.s IL_007d
IL_006d: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0072: pop
IL_0073: br.s IL_0083
IL_0075: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_007a: pop
IL_007b: br.s IL_0083
IL_007d: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_0082: pop
IL_0083: ldarg.1
IL_0084: ldc.i4.0
IL_0085: bgt.s IL_0049
IL_0087: ldarg.1
IL_0088: ldc.i4.1
IL_0089: add
IL_008a: starg.s count
IL_008c: ldarg.0
IL_008d: ldstr "do-while"
IL_0092: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0097: brtrue IL_0013
IL_009c: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00a1: pop
IL_00a2: ldloc.0
IL_00a3: ldc.i4.1
IL_00a4: add
IL_00a5: stloc.0
IL_00a6: ldloc.0
IL_00a7: ldarg.1
IL_00a8: blt IL_000d
IL_00ad: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00b2: pop
IL_00b3: ret
} // end of method Loops::Issue1395
.method public hidebysig instance void
ForLoop() cil managed
{

122
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.roslyn.il

@ -2508,6 +2508,128 @@ @@ -2508,6 +2508,128 @@
IL_0094: ret
} // end of method Loops::DoWhileLoop
.method public hidebysig instance void
Issue1395(int32 count) cil managed
{
// Code size 219 (0xdb)
.maxstack 2
.locals init (int32 V_0,
bool V_1,
bool V_2,
int32 V_3,
bool V_4,
bool V_5,
bool V_6)
IL_0000: nop
IL_0001: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0006: pop
IL_0007: ldc.i4.0
IL_0008: stloc.0
IL_0009: br IL_00c7
IL_000e: nop
IL_000f: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0014: pop
IL_0015: nop
IL_0016: nop
IL_0017: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_001c: pop
IL_001d: ldarg.0
IL_001e: ldstr "part1"
IL_0023: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_0028: stloc.1
IL_0029: ldloc.1
IL_002a: brfalse.s IL_0048
IL_002c: nop
IL_002d: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_0032: pop
IL_0033: ldarg.0
IL_0034: ldstr "restart"
IL_0039: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_003e: stloc.2
IL_003f: ldloc.2
IL_0040: brfalse.s IL_0045
IL_0042: nop
IL_0043: br.s IL_0016
IL_0045: nop
IL_0046: br.s IL_0050
IL_0048: nop
IL_0049: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_004e: pop
IL_004f: nop
IL_0050: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0055: pop
IL_0056: br.s IL_0098
IL_0058: nop
IL_0059: ldarg.1
IL_005a: stloc.3
IL_005b: ldloc.3
IL_005c: switch (
IL_007f,
IL_007f,
IL_007f,
IL_0087,
IL_008f,
IL_0087,
IL_0087)
IL_007d: br.s IL_008f
IL_007f: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_0084: pop
IL_0085: br.s IL_0097
IL_0087: call class [mscorlib]System.Collections.IDictionary [mscorlib]System.Environment::GetEnvironmentVariables()
IL_008c: pop
IL_008d: br.s IL_0097
IL_008f: call string[] [mscorlib]System.Environment::GetLogicalDrives()
IL_0094: pop
IL_0095: br.s IL_0097
IL_0097: nop
IL_0098: ldarg.1
IL_0099: ldc.i4.0
IL_009a: cgt
IL_009c: stloc.s V_4
IL_009e: ldloc.s V_4
IL_00a0: brtrue.s IL_0058
IL_00a2: ldarg.1
IL_00a3: ldc.i4.1
IL_00a4: add
IL_00a5: starg.s count
IL_00a7: nop
IL_00a8: ldarg.0
IL_00a9: ldstr "do-while"
IL_00ae: call instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.Loops::Condition(string)
IL_00b3: stloc.s V_5
IL_00b5: ldloc.s V_5
IL_00b7: brtrue IL_0015
IL_00bc: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00c1: pop
IL_00c2: nop
IL_00c3: ldloc.0
IL_00c4: ldc.i4.1
IL_00c5: add
IL_00c6: stloc.0
IL_00c7: ldloc.0
IL_00c8: ldarg.1
IL_00c9: clt
IL_00cb: stloc.s V_6
IL_00cd: ldloc.s V_6
IL_00cf: brtrue IL_000e
IL_00d4: call string[] [mscorlib]System.Environment::GetCommandLineArgs()
IL_00d9: pop
IL_00da: ret
} // end of method Loops::Issue1395
.method public hidebysig instance void
ForLoop() cil managed
{

10
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -858,12 +858,18 @@ namespace ICSharpCode.Decompiler.CSharp @@ -858,12 +858,18 @@ namespace ICSharpCode.Decompiler.CSharp
if (!container.MatchConditionBlock(continueTarget, out condition, out _))
throw new NotSupportedException("Invalid condition block in do-while loop.");
blockStatement = ConvertBlockContainer(new BlockStatement(), container, container.Blocks.SkipLast(1), true);
if (continueTarget.IncomingEdgeCount == continueCount) {
// Remove the entrypoint label if all jumps to the label were replaced with 'continue;' statements
if (container.EntryPoint.IncomingEdgeCount == 2) {
// Remove the entry-point label, if there are only two jumps to the entry-point:
// from outside the loop and from the condition-block.
blockStatement.Statements.First().Remove();
}
if (blockStatement.LastOrDefault() is ContinueStatement continueStmt3)
continueStmt3.Remove();
if (continueTarget.IncomingEdgeCount > continueCount) {
// if there are branches to the condition block, that were not converted
// to continue statements, we have to introduce an extra label.
blockStatement.Add(new LabelStatement { Label = continueTarget.Label });
}
if (blockStatement.Statements.Count == 0) {
return new WhileStatement {
Condition = exprBuilder.TranslateCondition(condition),

8
ICSharpCode.Decompiler/IL/Transforms/HighLevelLoopTransform.cs

@ -82,7 +82,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -82,7 +82,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
ConditionDetection.InvertIf(loopBody, ifInstruction, context);
}
context.Step("Transform to while (condition) loop", loop);
context.Step("Transform to while (condition) loop: " + loop.EntryPoint.Label, loop);
loop.Kind = ContainerKind.While;
//invert comparison
ifInstruction.Condition = Comp.LogicNot(ifInstruction.Condition);
@ -150,7 +150,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -150,7 +150,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// not a do-while loop, exit.
if (conditions == null || conditions.Count == 0)
return false;
context.Step("Transform to do-while loop", loop);
context.Step("Transform to do-while loop: " + loop.EntryPoint.Label, loop);
Block conditionBlock;
// first we remove all extracted instructions from the original block.
var originalBlock = (Block)exit.Parent;
@ -358,7 +358,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -358,7 +358,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// - increment block
if (incrementBlock.Instructions.Count <= 1 || loop.Blocks.Count < 3)
return false;
context.Step("Transform to for loop", loop);
context.Step("Transform to for loop: " + loop.EntryPoint.Label, loop);
// move the block to the end of the loop:
loop.Blocks.MoveElementToEnd(incrementBlock);
loop.Kind = ContainerKind.For;
@ -398,7 +398,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -398,7 +398,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
}
if (numberOfConditions == 0)
return false;
context.Step("Transform to for loop", loop);
context.Step("Transform to for loop: " + loop.EntryPoint.Label, loop);
// split condition block:
whileCondition.ReplaceWith(forCondition);
ExpressionTransforms.RunOnSingleStatement(forCondition, context);

Loading…
Cancel
Save