Browse Source

Fix #882: Invalid assignment code after decompiling

pull/881/merge
Siegfried Pammer 8 years ago
parent
commit
b5e46c3545
  1. 3
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 18
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs
  3. 56
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.il
  4. 49
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.opt.il
  5. 40
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.opt.roslyn.il
  6. 51
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.roslyn.il
  7. 2
      ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

3
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -115,9 +115,6 @@ @@ -115,9 +115,6 @@
</ItemGroup>
<ItemGroup>
<None Include="TestCases\Pretty\CompoundAssignmentTest.il">
<DependentUpon>CompoundAssignmentTest.cs</DependentUpon>
</None>
<None Include="TestCases\Pretty\HelloWorld.il">
<DependentUpon>HelloWorld.cs</DependentUpon>
</None>

18
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs

@ -54,7 +54,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -54,7 +54,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
}
private class Item
{
public Item Self;
}
private int test1;
private int[] array1;
private StructContainer field1;
@ -239,5 +244,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -239,5 +244,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
return ++CompoundAssignmentTest.StaticProperty;
}
private static Item GetItem(object obj)
{
return null;
}
private static void Issue882()
{
Item item = CompoundAssignmentTest.GetItem(null);
item.Self = item;
}
}
}

56
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.il

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly rtuqxf3v
.assembly wswrh1ww
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
@ -20,15 +20,15 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module rtuqxf3v.dll
// MVID: {0891498F-C2CF-4474-B2F7-31DC8C6C47C7}
.module wswrh1ww.dll
// MVID: {0FA9B26D-B874-4697-B526-76EF6D2DAD90}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x00DF0000
// Image base: 0x029E0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -137,6 +137,22 @@ @@ -137,6 +137,22 @@
} // end of property MutableClass::Item
} // end of class MutableClass
.class auto ansi nested private beforefieldinit Item
extends [mscorlib]System.Object
{
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item Self
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method Item::.ctor
} // end of class Item
.field private int32 test1
.field private int32[] array1
.field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/StructContainer field1
@ -860,6 +876,36 @@ @@ -860,6 +876,36 @@
IL_0013: ret
} // end of method CompoundAssignmentTest::PreIncrementStaticProperty
.method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item
GetItem(object obj) cil managed
{
// Code size 7 (0x7)
.maxstack 1
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item V_0)
IL_0000: nop
IL_0001: ldnull
IL_0002: stloc.0
IL_0003: br.s IL_0005
IL_0005: ldloc.0
IL_0006: ret
} // end of method CompoundAssignmentTest::GetItem
.method private hidebysig static void Issue882() cil managed
{
// Code size 16 (0x10)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item V_0)
IL_0000: nop
IL_0001: ldnull
IL_0002: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest::GetItem(object)
IL_0007: stloc.0
IL_0008: ldloc.0
IL_0009: ldloc.0
IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item::Self
IL_000f: ret
} // end of method CompoundAssignmentTest::Issue882
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -881,4 +927,4 @@ @@ -881,4 +927,4 @@
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file ../../../../ICSharpCode.Decompiler.Tests/TestCases/Pretty\CompoundAssignmentTest.res
// WARNING: Created Win32 resource file ../../../TestCases/Pretty\CompoundAssignmentTest.res

49
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.opt.il

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly mjdn04ya
.assembly ag42vicc
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
@ -20,15 +20,15 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module mjdn04ya.dll
// MVID: {D8AF2CB3-EE41-4B93-96CE-1FD07E5E4237}
.module ag42vicc.dll
// MVID: {EB752380-6A62-4B20-9497-B68A784C5BD7}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x01640000
// Image base: 0x00DE0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -125,6 +125,22 @@ @@ -125,6 +125,22 @@
} // end of property MutableClass::Item
} // end of class MutableClass
.class auto ansi nested private beforefieldinit Item
extends [mscorlib]System.Object
{
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item Self
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method Item::.ctor
} // end of class Item
.field private int32 test1
.field private int32[] array1
.field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/StructContainer field1
@ -713,6 +729,29 @@ @@ -713,6 +729,29 @@
IL_000d: ret
} // end of method CompoundAssignmentTest::PreIncrementStaticProperty
.method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item
GetItem(object obj) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldnull
IL_0001: ret
} // end of method CompoundAssignmentTest::GetItem
.method private hidebysig static void Issue882() cil managed
{
// Code size 15 (0xf)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item V_0)
IL_0000: ldnull
IL_0001: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest::GetItem(object)
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldloc.0
IL_0009: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item::Self
IL_000e: ret
} // end of method CompoundAssignmentTest::Issue882
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -734,4 +773,4 @@ @@ -734,4 +773,4 @@
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file ../../../../ICSharpCode.Decompiler.Tests/TestCases/Pretty\CompoundAssignmentTest.opt.res
// WARNING: Created Win32 resource file ../../../TestCases/Pretty\CompoundAssignmentTest.opt.res

40
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.opt.roslyn.il

@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module CompoundAssignmentTest.dll
// MVID: {0CCA0C51-2F8D-424C-BDE8-57699BE33BC6}
// MVID: {104CDF7A-FBAC-406D-AA60-4C777388A178}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x00900000
// Image base: 0x008E0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -129,6 +129,22 @@ @@ -129,6 +129,22 @@
} // end of property MutableClass::Item
} // end of class MutableClass
.class auto ansi nested private beforefieldinit Item
extends [mscorlib]System.Object
{
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item Self
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method Item::.ctor
} // end of class Item
.field private int32 test1
.field private int32[] array1
.field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/StructContainer field1
@ -716,6 +732,26 @@ @@ -716,6 +732,26 @@
IL_000d: ret
} // end of method CompoundAssignmentTest::PreIncrementStaticProperty
.method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item
GetItem(object obj) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldnull
IL_0001: ret
} // end of method CompoundAssignmentTest::GetItem
.method private hidebysig static void Issue882() cil managed
{
// Code size 13 (0xd)
.maxstack 8
IL_0000: ldnull
IL_0001: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest::GetItem(object)
IL_0006: dup
IL_0007: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item::Self
IL_000c: ret
} // end of method CompoundAssignmentTest::Issue882
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{

51
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.roslyn.il

@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module CompoundAssignmentTest.dll
// MVID: {572A9208-925A-4E92-9D86-8EC36FE271FC}
// MVID: {E4D6BDFE-1178-4790-A328-6755C028F1BE}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x00AF0000
// Image base: 0x00D10000
// =============== CLASS MEMBERS DECLARATION ===================
@ -138,6 +138,23 @@ @@ -138,6 +138,23 @@
} // end of property MutableClass::Item
} // end of class MutableClass
.class auto ansi nested private beforefieldinit Item
extends [mscorlib]System.Object
{
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item Self
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method Item::.ctor
} // end of class Item
.field private int32 test1
.field private int32[] array1
.field private valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/StructContainer field1
@ -856,6 +873,36 @@ @@ -856,6 +873,36 @@
IL_0013: ret
} // end of method CompoundAssignmentTest::PreIncrementStaticProperty
.method private hidebysig static class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item
GetItem(object obj) cil managed
{
// Code size 7 (0x7)
.maxstack 1
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item V_0)
IL_0000: nop
IL_0001: ldnull
IL_0002: stloc.0
IL_0003: br.s IL_0005
IL_0005: ldloc.0
IL_0006: ret
} // end of method CompoundAssignmentTest::GetItem
.method private hidebysig static void Issue882() cil managed
{
// Code size 16 (0x10)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item V_0)
IL_0000: nop
IL_0001: ldnull
IL_0002: call class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest::GetItem(object)
IL_0007: stloc.0
IL_0008: ldloc.0
IL_0009: ldloc.0
IL_000a: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item ICSharpCode.Decompiler.Tests.TestCases.Pretty.CompoundAssignmentTest/Item::Self
IL_000f: ret
} // end of method CompoundAssignmentTest::Issue882
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{

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

@ -90,7 +90,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -90,7 +90,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
block.Instructions.RemoveAt(i + 1);
} else if (nextInst is StObj) { // static fields
fieldStore = (StObj)nextInst;
if (!fieldStore.Value.MatchLdLoc(inst.Variable))
if (!fieldStore.Value.MatchLdLoc(inst.Variable) || (fieldStore.Target.MatchLdFlda(out var target, out _) && target.MatchLdLoc(inst.Variable)))
return false;
context.Step("Inline assignment to static field", fieldStore);
local = inst.Variable;

Loading…
Cancel
Save