Browse Source

TransformInlineAssignmentStObjOrCall: Make sure no dead store is produced by the transform.

pull/2755/head
Siegfried Pammer 3 years ago committed by Daniel Grunwald
parent
commit
c5ff0cafc5
  1. 3
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue684.cs
  2. 7
      ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

3
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue684.cs

@ -25,7 +25,8 @@ public static class Issue684 @@ -25,7 +25,8 @@ public static class Issue684
Console.WriteLine(num3);
for (; i <= num; i += num3)
{
int num4 = (array[i] = 1);
int num4 = 1;
array[i] = num4;
}
i = num3;
while (true)

7
ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

@ -122,6 +122,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -122,6 +122,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms
local = inst.Variable;
localStore = null;
nextPos = pos + 1;
if (local.LoadCount == 1 && local.AddressCount == 0)
{
// inline assignment would produce a dead store in this case, which is ugly
// and causes problems with the deconstruction transform.
return false;
}
}
if (block.Instructions[nextPos] is StObj stobj)
{

Loading…
Cancel
Save