Browse Source

Fix #2129: be more flexible about the initialization order for the async state machine.

pull/2145/head
Daniel Grunwald 5 years ago
parent
commit
b035ec1960
  1. 26
      ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs

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

@ -347,20 +347,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
return false; return false;
if (initialState != -1) if (initialState != -1)
return false; return false;
pos--;
// Check the second-to-last field assignment - this should be the builder field
// stfld StateMachine.builder(ldloca stateMachine, call Create())
if (pos < 0)
return false;
if (!MatchStFld(body[pos], stateMachineVar, out var builderField3, out var builderInitialization))
return false;
if (builderField3 != builderField)
return false;
if (!(builderInitialization is Call createCall))
return false;
if (createCall.Method.Name != "Create" || createCall.Arguments.Count != 0)
return false;
int stopPos = pos; int stopPos = pos;
pos = 0; pos = 0;
@ -374,12 +360,20 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
return false; return false;
pos++; pos++;
} }
bool builderFieldIsInitialized = false;
for (; pos < stopPos; pos++) for (; pos < stopPos; pos++)
{ {
// stfld StateMachine.field(ldloca stateMachine, ldvar(param)) // stfld StateMachine.field(ldloca stateMachine, ldvar(param))
if (!MatchStFld(body[pos], stateMachineVar, out var field, out var fieldInit)) if (!MatchStFld(body[pos], stateMachineVar, out var field, out var fieldInit))
return false; return false;
if (fieldInit.MatchLdLoc(out var v) && v.Kind == VariableKind.Parameter) if (field == builderField)
{
// stfld StateMachine.builder(ldloca stateMachine, call Create())
if (!(fieldInit is Call { Method: { Name: "Create" }, Arguments: { Count: 0 } }))
return false;
builderFieldIsInitialized = true;
}
else if (fieldInit.MatchLdLoc(out var v) && v.Kind == VariableKind.Parameter)
{ {
// OK, copies parameter into state machine // OK, copies parameter into state machine
fieldToParameterMap[field] = v; fieldToParameterMap[field] = v;
@ -395,7 +389,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
} }
} }
return true; return builderFieldIsInitialized;
} }
/// <summary> /// <summary>

Loading…
Cancel
Save