Browse Source

Remove MarkGeneratedVariables() step in AsyncAwaitDecompiler.

This was left-over from earlier versions; but ILSpy stopped caring so much about variable vs. stack slot since Roslyn started to optimize more aggressively.
The change of variable type caused problems for debug information and could even cause an assertion.

Closes #1456, closes #1562.
pull/1612/head
Daniel Grunwald 6 years ago
parent
commit
beed6b5e24
  1. 4
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  2. 12
      ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs
  3. 2
      ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs

4
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -712,7 +712,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -712,7 +712,9 @@ namespace ICSharpCode.Decompiler.CSharp
// Must be a plain assignment expression and variable must only be used in 'body' + only assigned once.
if (stloc.Parent == loopBody && VariableIsOnlyUsedInBlock(stloc, usingContainer)) {
foreachVariable = stloc.Variable;
return RequiredGetCurrentTransformation.UseExistingVariable;
if (foreachVariable.Kind == VariableKind.Local) {
return RequiredGetCurrentTransformation.UseExistingVariable;
}
}
}
// In optimized Roslyn code it can happen that the foreach variable is referenced via addressof

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

@ -128,7 +128,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -128,7 +128,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
CleanDoFinallyBodies(function);
context.Step("Translate fields to local accesses", function);
MarkGeneratedVariables(function);
YieldReturnDecompiler.TranslateFieldsToLocalAccess(function, function, fieldToParameterMap);
TranslateCachedFieldsToLocals();
@ -902,17 +901,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -902,17 +901,6 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
}
#endregion
void MarkGeneratedVariables(ILFunction function)
{
// Variables after the awaiters are usually compiler-generated;
// so mark them as stack slots.
foreach (var v in function.Variables) {
if (v.Kind == VariableKind.Local && v.Index >= smallestAwaiterVarIndex) {
v.Kind = VariableKind.StackSlot;
}
}
}
/// <summary>
/// Eliminates usage of doFinallyBodies
/// </summary>

2
ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs

@ -76,6 +76,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -76,6 +76,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false;
if (!(storeInst.Value.MatchLdNull() || CheckResourceType(storeInst.Variable.Type)))
return false;
if (storeInst.Variable.Kind != VariableKind.Local)
return false;
if (storeInst.Variable.LoadInstructions.Any(ld => !ld.IsDescendantOf(tryFinally)))
return false;
if (storeInst.Variable.AddressInstructions.Any(la => !la.IsDescendantOf(tryFinally) || (la.IsDescendantOf(tryFinally.TryBlock) && !ILInlining.IsUsedAsThisPointerInCall(la))))

Loading…
Cancel
Save