Browse Source

Fix bug in TransformArrayInitializers: local storage was deleted.

pull/870/head
Siegfried Pammer 8 years ago
parent
commit
9a78b85576
  1. 17
      ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs

17
ICSharpCode.Decompiler/IL/Transforms/TransformArrayInitializers.cs

@ -64,9 +64,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return true; return true;
} }
if (arrayLength.Length == 1) { if (arrayLength.Length == 1) {
ILVariable finalStore;
int instructionsToRemove; int instructionsToRemove;
if (HandleSimpleArrayInitializer(body, pos + 1, v, arrayLength[0], out finalStore, out values, out instructionsToRemove)) { if (HandleSimpleArrayInitializer(body, pos + 1, v, arrayLength[0], out values, out instructionsToRemove)) {
context.Step("HandleSimpleArrayInitializer", inst); context.Step("HandleSimpleArrayInitializer", inst);
var block = new Block(BlockType.ArrayInitializer); var block = new Block(BlockType.ArrayInitializer);
var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type); var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type);
@ -79,13 +78,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
)); ));
block.FinalInstruction = new LdLoc(tempStore); block.FinalInstruction = new LdLoc(tempStore);
body.Instructions[pos].ReplaceWith(new StLoc(finalStore ?? v, block)); body.Instructions[pos].ReplaceWith(new StLoc(v, block));
RemoveInstructions(body, pos + 1, instructionsToRemove); RemoveInstructions(body, pos + 1, instructionsToRemove);
//body.Instructions.RemoveRange(pos + 1, values.Length + 1);
ILInlining.InlineIfPossible(body, ref pos, context); ILInlining.InlineIfPossible(body, ref pos, context);
return true; return true;
} }
if (HandleJaggedArrayInitializer(body, pos + 1, v, arrayLength[0], out finalStore, out values, out instructionsToRemove)) { if (HandleJaggedArrayInitializer(body, pos + 1, v, arrayLength[0], out ILVariable finalStore, out values, out instructionsToRemove)) {
context.Step("HandleJaggedArrayInitializer", inst); context.Step("HandleJaggedArrayInitializer", inst);
var block = new Block(BlockType.ArrayInitializer); var block = new Block(BlockType.ArrayInitializer);
var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type); var tempStore = context.Function.RegisterVariable(VariableKind.InitializerTarget, v.Type);
@ -170,11 +168,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// <summary> /// <summary>
/// Handle simple case where RuntimeHelpers.InitializeArray is not used. /// Handle simple case where RuntimeHelpers.InitializeArray is not used.
/// </summary> /// </summary>
bool HandleSimpleArrayInitializer(Block block, int pos, ILVariable store, int length, out ILVariable finalStore, out ILInstruction[] values, out int instructionsToRemove) bool HandleSimpleArrayInitializer(Block block, int pos, ILVariable store, int length, out ILInstruction[] values, out int instructionsToRemove)
{ {
instructionsToRemove = 0; instructionsToRemove = 0;
values = null; values = null;
finalStore = null;
values = new ILInstruction[length]; values = new ILInstruction[length];
int index = 0; int index = 0;
int elementCount = 0; int elementCount = 0;
@ -193,14 +190,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
elementCount++; elementCount++;
instructionsToRemove++; instructionsToRemove++;
} }
ILInstruction array;
if (pos + elementCount >= block.Instructions.Count) if (pos + elementCount >= block.Instructions.Count)
return false; return false;
if (block.Instructions[pos + elementCount].MatchStLoc(out finalStore, out array) && array.MatchLdLoc(store)) {
instructionsToRemove++;
} else {
finalStore = store;
}
return elementCount > 0; return elementCount > 0;
} }

Loading…
Cancel
Save