Skip to content
Permalink
Browse files

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

  • Loading branch information
dgrunwald committed Feb 14, 2020
1 parent 350c54d commit 4b1f0b342c519e5fae217008fdc634fcf2db4d62
@@ -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" />
@@ -185,6 +185,23 @@ public static async Task InfiniteLoopWithAwait()
}
}

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()
{
@@ -623,14 +623,18 @@ void CheckSetResultAndExitBlock(BlockContainer blockContainer)
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 @@ void CheckSetResultAndExitBlock(BlockContainer blockContainer)
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 @@ void CheckSetResultAndExitBlock(BlockContainer blockContainer)
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 @@ void ValidateCatchBlock()
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 @@ void ValidateCatchBlock()
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])))
@@ -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" />
@@ -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" />

0 comments on commit 4b1f0b3

Please sign in to comment.
You can’t perform that action at this time.