From 1b505b8c6d91c779fe356105c8b4b85f3331245e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 10 Nov 2019 15:56:49 +0100 Subject: [PATCH] Adjust async-streams decompiler for dotnet/roslyn#39436 --- .../ICSharpCode.Decompiler.Tests.csproj | 4 +-- .../IL/ControlFlow/AsyncAwaitDecompiler.cs | 25 ++++++++++++++----- ILSpy.Tests/ILSpy.Tests.csproj | 4 +-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index c96dd0b67..a3070ae32 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -42,8 +42,8 @@ - - + + diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs index 8b4862c6c..d41409719 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs @@ -625,9 +625,8 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow } // stobj System.Int32(ldflda [Field ICSharpCode.Decompiler.Tests.TestCases.Pretty.Async+d__7.<>1__state](ldloc this), ldc.i4 -2) // call SetResult(ldflda [Field ICSharpCode.Decompiler.Tests.TestCases.Pretty.Async+d__7.<>t__builder](ldloc this), ldloc result) + // [optional] call Complete(ldflda <>t__builder(ldloc this)) // leave IL_0000 - if (setResultAndExitBlock.Instructions.Count != 3) - throw new SymbolicAnalysisFailedException(); if (!MatchStateAssignment(setResultAndExitBlock.Instructions[0], out finalState)) throw new SymbolicAnalysisFailedException(); finalStateKnown = true; @@ -657,7 +656,13 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow throw new SymbolicAnalysisFailedException(); break; } - if (!setResultAndExitBlock.Instructions[2].MatchLeave(blockContainer)) + int pos = 2; + if (MatchCall(setResultAndExitBlock.Instructions[pos], "Complete", out args)) { + if (!(args.Count == 1 && IsBuilderFieldOnThis(args[0]))) + throw new SymbolicAnalysisFailedException(); + pos++; + } + if (!setResultAndExitBlock.Instructions[pos].MatchLeave(blockContainer)) throw new SymbolicAnalysisFailedException(); } @@ -668,6 +673,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow // stloc exception(ldloc E_143) // stfld <>1__state(ldloc this, ldc.i4 -2) // call SetException(ldfld <>t__builder(ldloc this), ldloc exception) + // [optional] call Complete(ldfld <>t__builder(ldloc this)) // leave IL_0000 // } // } @@ -682,8 +688,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow if (catchBlock == null) throw new SymbolicAnalysisFailedException(); catchHandlerOffset = catchBlock.StartILOffset; - if (catchBlock.Instructions.Count != 4) - throw new SymbolicAnalysisFailedException(); // stloc exception(ldloc E_143) if (!(catchBlock.Instructions[0] is StLoc stloc)) throw new SymbolicAnalysisFailedException(); @@ -708,8 +712,17 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow throw new SymbolicAnalysisFailedException(); if (!args[1].MatchLdLoc(stloc.Variable)) throw new SymbolicAnalysisFailedException(); + + int pos = 3; + // [optional] call Complete(ldfld <>t__builder(ldloc this)) + if (MatchCall(catchBlock.Instructions[pos], "Complete", out args)) { + if (!(args.Count == 1 && IsBuilderFieldOnThis(args[0]))) + throw new SymbolicAnalysisFailedException(); + pos++; + } + // leave IL_0000 - if (!catchBlock.Instructions[3].MatchLeave((BlockContainer)moveNextFunction.Body)) + if (!catchBlock.Instructions[pos].MatchLeave((BlockContainer)moveNextFunction.Body)) throw new SymbolicAnalysisFailedException(); } diff --git a/ILSpy.Tests/ILSpy.Tests.csproj b/ILSpy.Tests/ILSpy.Tests.csproj index 32c81dd25..901e19667 100644 --- a/ILSpy.Tests/ILSpy.Tests.csproj +++ b/ILSpy.Tests/ILSpy.Tests.csproj @@ -42,8 +42,8 @@ - - + +