Browse Source

Fix await calls not getting decompiled correctly (#904)

pull/909/merge
Moritz 8 years ago committed by Daniel Grunwald
parent
commit
f4209947a0
  1. 4
      ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
  2. 15
      ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs

4
ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs

@ -198,8 +198,8 @@ namespace ICSharpCode.Decompiler.Tests
RunCS(options: options); RunCS(options: options);
} }
[Test, Ignore("Run() method cannot be fully decompiled.")] [Test]
public void Async([ValueSource("defaultOptions")] CompilerOptions options) public void Async([Values(CompilerOptions.None, CompilerOptions.Optimize)] CompilerOptions options)
{ {
RunCS(options: options); RunCS(options: options);
} }

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

@ -774,17 +774,26 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
return false; return false;
if (!target.MatchLdThis()) if (!target.MatchLdThis())
return false; return false;
if (field.MemberDefinition != awaiterField) if (!field.Equals(awaiterField))
return false; return false;
pos++; pos++;
// stfld awaiterField(ldloc this, default.value) // stfld awaiterField(ldloc this, default.value)
if (block.Instructions[pos].MatchStFld(out target, out field, out value) if (block.Instructions[pos].MatchStFld(out target, out field, out value)
&& target.MatchLdThis() && target.MatchLdThis()
&& field.MemberDefinition == awaiterField && field.Equals(awaiterField)
&& value.OpCode == OpCode.DefaultValue) && value.OpCode == OpCode.DefaultValue)
{ {
pos++; pos++;
} else {
// {stloc V_6(default.value System.Runtime.CompilerServices.TaskAwaiter)}
// {stobj System.Runtime.CompilerServices.TaskAwaiter`1[[System.Int32]](ldflda <>u__$awaiter4(ldloc this), ldloc V_6) at IL_0163}
if (block.Instructions[pos].MatchStLoc(out var variable, out value) && value.OpCode == OpCode.DefaultValue
&& block.Instructions[pos + 1].MatchStFld(out target, out field, out value)
&& field.Equals(awaiterField)
&& value.MatchLdLoc(variable)) {
pos += 2;
}
} }
// stloc S_28(ldc.i4 -1) // stloc S_28(ldc.i4 -1)
@ -804,7 +813,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
if (block.Instructions[pos].MatchStFld(out target, out field, out value)) { if (block.Instructions[pos].MatchStFld(out target, out field, out value)) {
if (!target.MatchLdThis()) if (!target.MatchLdThis())
return false; return false;
if (field.MemberDefinition != stateField) if (!field.MemberDefinition.Equals(stateField.MemberDefinition))
return false; return false;
if (!(value.MatchLdcI4(initialState) || value.MatchLdLoc(m1Var))) if (!(value.MatchLdcI4(initialState) || value.MatchLdLoc(m1Var)))
return false; return false;

Loading…
Cancel
Save