Browse Source

Fix #1925: Adjust AsyncAwaitDecompiler to changes in Roslyn 3.5.0-beta2

pull/1930/head
Daniel Grunwald 5 years ago
parent
commit
4b1f0b342c
  1. 4
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 17
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs
  3. 33
      ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs
  4. 4
      ILSpy.Tests/ILSpy.Tests.csproj
  5. 2
      ILSpy/ILSpy.csproj

4
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -42,8 +42,8 @@ @@ -42,8 +42,8 @@
<ItemGroup>
<PackageReference Include="DiffLib" Version="2017.7.26.1241" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0-beta3-final" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.4.0-beta3-final" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.5.0-beta2-final" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.5.0-beta2-final" />
<PackageReference Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta1-63314-01" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />

17
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs

@ -185,6 +185,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -185,6 +185,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
public async Task AsyncWithLocalVar()
{
object a = new object();
#if CS70
(object, string) tuple = (new object(), "abc");
#endif
await UseObj(a);
await UseObj(a);
#if CS70
await UseObj(tuple);
#endif
}
public static async Task UseObj(object a)
{
}
#if CS70
public static async Task<int> AsyncLocalFunctions()
{

33
ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs

@ -623,14 +623,18 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -623,14 +623,18 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
finalStateKnown = false; // final state will be detected in ValidateCatchBlock() instead
return;
}
// stobj System.Int32(ldflda [Field ICSharpCode.Decompiler.Tests.TestCases.Pretty.Async+<SimpleBoolTaskMethod>d__7.<>1__state](ldloc this), ldc.i4 -2)
// call SetResult(ldflda [Field ICSharpCode.Decompiler.Tests.TestCases.Pretty.Async+<SimpleBoolTaskMethod>d__7.<>t__builder](ldloc this), ldloc result)
// stfld <>1__state(ldloc this, ldc.i4 -2)
// [optional] stfld <>u__N(ldloc this, ldnull)
// call SetResult(ldflda <>t__builder(ldloc this), ldloc result)
// [optional] call Complete(ldflda <>t__builder(ldloc this))
// leave IL_0000
if (!MatchStateAssignment(setResultAndExitBlock.Instructions[0], out finalState))
int pos = 0;
if (!MatchStateAssignment(setResultAndExitBlock.Instructions[pos], out finalState))
throw new SymbolicAnalysisFailedException();
finalStateKnown = true;
if (!MatchCall(setResultAndExitBlock.Instructions[1], "SetResult", out var args))
pos++;
MatchHoistedLocalCleanup(setResultAndExitBlock, ref pos);
if (!MatchCall(setResultAndExitBlock.Instructions[pos], "SetResult", out var args))
throw new SymbolicAnalysisFailedException();
if (!IsBuilderOrPromiseFieldOnThis(args[0]))
throw new SymbolicAnalysisFailedException();
@ -656,7 +660,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -656,7 +660,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
throw new SymbolicAnalysisFailedException();
break;
}
int pos = 2;
pos++;
if (MatchCall(setResultAndExitBlock.Instructions[pos], "Complete", out args)) {
if (!(args.Count == 1 && IsBuilderFieldOnThis(args[0])))
throw new SymbolicAnalysisFailedException();
@ -666,12 +670,25 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -666,12 +670,25 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
throw new SymbolicAnalysisFailedException();
}
private void MatchHoistedLocalCleanup(Block block, ref int pos)
{
while (block.Instructions[pos].MatchStFld(out var target, out _, out var value)) {
// https://github.com/dotnet/roslyn/pull/39735 hoisted local cleanup
if (!target.MatchLdThis())
throw new SymbolicAnalysisFailedException();
if (!(value.MatchLdNull() || value is DefaultValue))
throw new SymbolicAnalysisFailedException();
pos++;
}
}
void ValidateCatchBlock()
{
// catch E_143 : System.Exception if (ldc.i4 1) BlockContainer {
// Block IL_008f (incoming: 1) {
// stloc exception(ldloc E_143)
// stfld <>1__state(ldloc this, ldc.i4 -2)
// [optional] stfld <>u__N(ldloc this, ldnull)
// call SetException(ldfld <>t__builder(ldloc this), ldloc exception)
// [optional] call Complete(ldfld <>t__builder(ldloc this))
// leave IL_0000
@ -703,8 +720,10 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -703,8 +720,10 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
finalState = newState;
finalStateKnown = true;
}
int pos = 2;
MatchHoistedLocalCleanup(catchBlock, ref pos);
// call SetException(ldfld <>t__builder(ldloc this), ldloc exception)
if (!MatchCall(catchBlock.Instructions[2], "SetException", out var args))
if (!MatchCall(catchBlock.Instructions[pos], "SetException", out var args))
throw new SymbolicAnalysisFailedException();
if (args.Count != 2)
throw new SymbolicAnalysisFailedException();
@ -713,7 +732,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -713,7 +732,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
if (!args[1].MatchLdLoc(stloc.Variable))
throw new SymbolicAnalysisFailedException();
int pos = 3;
pos++;
// [optional] call Complete(ldfld <>t__builder(ldloc this))
if (MatchCall(catchBlock.Instructions[pos], "Complete", out args)) {
if (!(args.Count == 1 && IsBuilderFieldOnThis(args[0])))

4
ILSpy.Tests/ILSpy.Tests.csproj

@ -42,8 +42,8 @@ @@ -42,8 +42,8 @@
<ItemGroup>
<PackageReference Include="DiffLib" Version="2017.7.26.1241" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0-beta3-final" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.4.0-beta3-final" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.5.0-beta2-final" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.5.0-beta2-final" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="NUnit" Version="3.11.0" />

2
ILSpy/ILSpy.csproj

@ -467,7 +467,7 @@ @@ -467,7 +467,7 @@
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Condition=" '$(COMPUTERNAME)' != 'DANIEL-E590' " Include="Properties\Resources.zh-Hans.resx" />
<EmbeddedResource Include="Properties\Resources.zh-Hans.resx" />
<Resource Include="Images\ILSpy.ico" />
<EmbeddedResource Include="TextView\CSharp-Mode.xshd" />
<EmbeddedResource Include="TextView\ILAsm-Mode.xshd" />

Loading…
Cancel
Save