Browse Source

Remove dead compiler-generated 'V = null;' assignments.

pull/734/merge
Daniel Grunwald 8 years ago
parent
commit
9fa6009c44
  1. 5
      ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs
  2. 11
      ICSharpCode.Decompiler/IL/Transforms/RemoveDeadVariableInit.cs

5
ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs

@ -126,6 +126,11 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
PrintFinallyMethodStateRanges(newBody); PrintFinallyMethodStateRanges(newBody);
// Add state machine field meta-data to parameter ILVariables.
foreach (var (f, p) in fieldToParameterMap) {
p.StateMachineField = f;
}
context.Step("Delete unreachable blocks", function); context.Step("Delete unreachable blocks", function);
// Note: because this only deletes blocks outright, the 'stateChanges' entries remain valid // Note: because this only deletes blocks outright, the 'stateChanges' entries remain valid
// (though some may point to now-deleted blocks) // (though some may point to now-deleted blocks)

11
ICSharpCode.Decompiler/IL/Transforms/RemoveDeadVariableInit.cs

@ -23,6 +23,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// <summary> /// <summary>
/// Remove <c>HasInitialValue</c> from locals that are definitely assigned before every use /// Remove <c>HasInitialValue</c> from locals that are definitely assigned before every use
/// (=the initial value is a dead store). /// (=the initial value is a dead store).
///
/// In yield return generators, additionally removes dead 'V = null;' assignments.
/// </summary> /// </summary>
public class RemoveDeadVariableInit : IILTransform public class RemoveDeadVariableInit : IILTransform
{ {
@ -35,6 +37,15 @@ namespace ICSharpCode.Decompiler.IL.Transforms
v.HasInitialValue = false; v.HasInitialValue = false;
} }
} }
if (function.IsIterator) {
foreach (var v in function.Variables) {
if (v.Kind != VariableKind.Parameter && v.StoreCount == 1 && v.LoadCount == 0 && v.AddressCount == 0) {
if (v.StoreInstructions[0] is StLoc stloc && stloc.Value.MatchLdNull() && stloc.Parent is Block block) {
block.Instructions.Remove(stloc);
}
}
}
}
} }
} }
} }

Loading…
Cancel
Save