From ebf213d85efaf469f4f2bfcee0ee7ac043429be2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 27 Jan 2018 08:29:17 +0100 Subject: [PATCH] Fix #1047: Unsupported method --- .../ICSharpCode.Decompiler.Tests.csproj | 2 + .../ILPrettyTestRunner.cs | 6 ++ .../TestCases/ILPretty/Issue1047.cs | 24 +++++++ .../TestCases/ILPretty/Issue1047.il | 72 +++++++++++++++++++ .../CSharp/StatementBuilder.cs | 2 +- 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index e8db37154..e74d0d3b7 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -62,6 +62,7 @@ + @@ -70,6 +71,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs index 1ac579183..d7b6ebefb 100644 --- a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs @@ -54,6 +54,12 @@ namespace ICSharpCode.Decompiler.Tests Run(); } + [Test] + public void Issue1047() + { + Run(); + } + [Test] public void FSharpUsing_Debug() { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs new file mode 100644 index 000000000..aa82c2761 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.cs @@ -0,0 +1,24 @@ +namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty +{ + public class Issue1047 + { + private void ProblemMethod() + { + IL_0000: + do { + if (/*Error near IL_0001: Stack underflow*/ >= /*Error near IL_0001: Stack underflow*/) { + if ((int)/*Error near IL_0007: Stack underflow*/ == 0) { + return; + } + return; + } + } while ((int)/*Error near IL_0014: Stack underflow*/ == 0); + if (/*Error near IL_0020: Stack underflow*/ > /*Error near IL_0020: Stack underflow*/&& (int)/*Error near IL_0026: Stack underflow*/ != 0 && (int)/*Error near IL_002c: Stack underflow*/ == 0) { + return; + } + return; + IL_0037: + goto IL_0000; + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.il b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.il new file mode 100644 index 000000000..8600ee1bf --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1047.il @@ -0,0 +1,72 @@ +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly extern System +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly extern System.Core +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly ConsoleApp11 +{ + .ver 1:0:0:0 +} +.module ConsoleApp11.exe +// MVID: {B973FCD6-A9C4-48A9-8291-26DDC248E208} +.imagebase 0x00400000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00020003 // ILONLY 32BITPREFERRED +// Image base: 0x000001C4B6C90000 + +.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue1047 +{ + .method private hidebysig instance void ProblemMethod() cil managed + { + .maxstack 4 + + // loop start + IL_0000: nop + blt IL_0047 + + nop + brfalse IL_0037 + + nop + + IL_0037: nop + br L_exit + + IL_0047: nop + brtrue IL_0083 + + nop + br IL_0000 + + IL_0083: nop + ble.un IL_00fa + + nop + brfalse IL_00db + + nop + brfalse IL_00fa + + IL_00db: nop + + IL_00fa: br L_exit + + br IL_0000 + // end loop + + L_exit: ret + } +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index f9cdec17a..13ab318f4 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -723,7 +723,7 @@ namespace ICSharpCode.Decompiler.CSharp protected internal override Statement VisitBlockContainer(BlockContainer container) { - if (container.EntryPoint.IncomingEdgeCount > 1) { + if (container.Kind != ContainerKind.Normal && container.EntryPoint.IncomingEdgeCount > 1) { var oldContinueTarget = continueTarget; var oldContinueCount = continueCount; var oldBreakTarget = breakTarget;