Browse Source

Fix #951: Incorrect decompilation of anonymous delegate

pull/925/merge
Siegfried Pammer 8 years ago
parent
commit
8135157e95
  1. 33
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs
  2. 211
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il
  3. 179
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il
  4. 175
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il
  5. 203
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il
  6. 10
      ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs

33
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs

@ -87,6 +87,39 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
new Thread((ThreadStart)delegate { new Thread((ThreadStart)delegate {
}); });
} }
public void Bug951(int amount)
{
this.DoAction(delegate {
if (amount < 0) {
amount = 0;
}
this.DoAction(delegate {
this.NoOp(amount);
});
});
}
public void Bug951b()
{
int amount = this.Foo();
this.DoAction(delegate {
if (amount < 0) {
amount = 0;
}
this.DoAction(delegate {
this.NoOp(amount);
});
});
}
private void DoAction(Action action)
{
}
private void NoOp(int a)
{
}
} }
public static void Test(this string a) public static void Test(this string a)

211
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.il

@ -15,7 +15,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0 .ver 4:0:0:0
} }
.assembly '3jzwaefw' .assembly uuulcfez
{ {
.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.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 )
@ -26,15 +26,15 @@
.hash algorithm 0x00008004 .hash algorithm 0x00008004
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module '3jzwaefw.dll' .module uuulcfez.dll
// MVID: {915B6C12-1305-49DC-868B-18153BA75025} // MVID: {018169C5-0E25-41DF-A239-DEF2F357B8C3}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x012B0000 // Image base: 0x00E90000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -213,6 +213,138 @@
} // end of class '<>c__DisplayClass30' } // end of class '<>c__DisplayClass30'
.class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass38'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this'
.field public int32 amount
.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 '<>c__DisplayClass38'::.ctor
.method public hidebysig instance void
'<Bug951>b__36'() cil managed
{
// Code size 51 (0x33)
.maxstack 3
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::amount
IL_0007: ldc.i4.0
IL_0008: clt
IL_000a: ldc.i4.0
IL_000b: ceq
IL_000d: stloc.0
IL_000e: ldloc.0
IL_000f: brtrue.s IL_001a
IL_0011: nop
IL_0012: ldarg.0
IL_0013: ldc.i4.0
IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::amount
IL_0019: nop
IL_001a: ldarg.0
IL_001b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<>4__this'
IL_0020: ldarg.0
IL_0021: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<Bug951>b__37'()
IL_0027: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_002c: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0031: nop
IL_0032: ret
} // end of method '<>c__DisplayClass38'::'<Bug951>b__36'
.method public hidebysig instance void
'<Bug951>b__37'() cil managed
{
// Code size 20 (0x14)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<>4__this'
IL_0007: ldarg.0
IL_0008: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::amount
IL_000d: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::NoOp(int32)
IL_0012: nop
IL_0013: ret
} // end of method '<>c__DisplayClass38'::'<Bug951>b__37'
} // end of class '<>c__DisplayClass38'
.class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass3c'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public int32 amount
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this'
.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 '<>c__DisplayClass3c'::.ctor
.method public hidebysig instance void
'<Bug951b>b__3a'() cil managed
{
// Code size 51 (0x33)
.maxstack 3
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::amount
IL_0007: ldc.i4.0
IL_0008: clt
IL_000a: ldc.i4.0
IL_000b: ceq
IL_000d: stloc.0
IL_000e: ldloc.0
IL_000f: brtrue.s IL_001a
IL_0011: nop
IL_0012: ldarg.0
IL_0013: ldc.i4.0
IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::amount
IL_0019: nop
IL_001a: ldarg.0
IL_001b: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<>4__this'
IL_0020: ldarg.0
IL_0021: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<Bug951b>b__3b'()
IL_0027: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_002c: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0031: nop
IL_0032: ret
} // end of method '<>c__DisplayClass3c'::'<Bug951b>b__3a'
.method public hidebysig instance void
'<Bug951b>b__3b'() cil managed
{
// Code size 20 (0x14)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<>4__this'
IL_0007: ldarg.0
IL_0008: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::amount
IL_000d: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::NoOp(int32)
IL_0012: nop
IL_0013: ret
} // end of method '<>c__DisplayClass3c'::'<Bug951b>b__3b'
} // end of class '<>c__DisplayClass3c'
.field private static class [mscorlib]System.Threading.ThreadStart 'CS$<>9__CachedAnonymousMethodDelegate35' .field private static class [mscorlib]System.Threading.ThreadStart 'CS$<>9__CachedAnonymousMethodDelegate35'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig instance class [mscorlib]System.Action .method public hidebysig instance class [mscorlib]System.Action
@ -560,6 +692,77 @@
IL_0026: ret IL_0026: ret
} // end of method InstanceTests::Bug955 } // end of method InstanceTests::Bug955
.method public hidebysig instance void
Bug951(int32 amount) cil managed
{
// Code size 42 (0x2a)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38' V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldarg.1
IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::amount
IL_000d: ldloc.0
IL_000e: ldarg.0
IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<>4__this'
IL_0014: nop
IL_0015: ldarg.0
IL_0016: ldloc.0
IL_0017: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<Bug951>b__36'()
IL_001d: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0022: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0027: nop
IL_0028: nop
IL_0029: ret
} // end of method InstanceTests::Bug951
.method public hidebysig instance void
Bug951b() cil managed
{
// Code size 47 (0x2f)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c' V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldarg.0
IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<>4__this'
IL_000d: nop
IL_000e: ldloc.0
IL_000f: ldarg.0
IL_0010: call instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Foo()
IL_0015: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::amount
IL_001a: ldarg.0
IL_001b: ldloc.0
IL_001c: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<Bug951b>b__3a'()
IL_0022: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0027: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_002c: nop
IL_002d: nop
IL_002e: ret
} // end of method InstanceTests::Bug951b
.method private hidebysig instance void
DoAction(class [mscorlib]System.Action action) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method InstanceTests::DoAction
.method private hidebysig instance void
NoOp(int32 a) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method InstanceTests::NoOp
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

179
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.il

@ -15,7 +15,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0 .ver 4:0:0:0
} }
.assembly kmdztkbc .assembly q15gqlgx
{ {
.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.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
.custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 )
@ -26,15 +26,15 @@
.hash algorithm 0x00008004 .hash algorithm 0x00008004
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module kmdztkbc.dll .module q15gqlgx.dll
// MVID: {901EEE35-CE14-4A96-8202-0E758AD0E8B0} // MVID: {0ECBA5A5-AD56-41FA-BC89-44E9A1AE0799}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x02C00000 // Image base: 0x00D00000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -210,6 +210,114 @@
} // end of class '<>c__DisplayClass30' } // end of class '<>c__DisplayClass30'
.class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass38'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this'
.field public int32 amount
.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 '<>c__DisplayClass38'::.ctor
.method public hidebysig instance void
'<Bug951>b__36'() cil managed
{
// Code size 40 (0x28)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::amount
IL_0006: ldc.i4.0
IL_0007: bge.s IL_0010
IL_0009: ldarg.0
IL_000a: ldc.i4.0
IL_000b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::amount
IL_0010: ldarg.0
IL_0011: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<>4__this'
IL_0016: ldarg.0
IL_0017: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<Bug951>b__37'()
IL_001d: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0022: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0027: ret
} // end of method '<>c__DisplayClass38'::'<Bug951>b__36'
.method public hidebysig instance void
'<Bug951>b__37'() cil managed
{
// Code size 18 (0x12)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<>4__this'
IL_0006: ldarg.0
IL_0007: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::amount
IL_000c: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::NoOp(int32)
IL_0011: ret
} // end of method '<>c__DisplayClass38'::'<Bug951>b__37'
} // end of class '<>c__DisplayClass38'
.class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass3c'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public int32 amount
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this'
.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 '<>c__DisplayClass3c'::.ctor
.method public hidebysig instance void
'<Bug951b>b__3a'() cil managed
{
// Code size 40 (0x28)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::amount
IL_0006: ldc.i4.0
IL_0007: bge.s IL_0010
IL_0009: ldarg.0
IL_000a: ldc.i4.0
IL_000b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::amount
IL_0010: ldarg.0
IL_0011: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<>4__this'
IL_0016: ldarg.0
IL_0017: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<Bug951b>b__3b'()
IL_001d: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0022: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0027: ret
} // end of method '<>c__DisplayClass3c'::'<Bug951b>b__3a'
.method public hidebysig instance void
'<Bug951b>b__3b'() cil managed
{
// Code size 18 (0x12)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<>4__this'
IL_0006: ldarg.0
IL_0007: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::amount
IL_000c: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::NoOp(int32)
IL_0011: ret
} // end of method '<>c__DisplayClass3c'::'<Bug951b>b__3b'
} // end of class '<>c__DisplayClass3c'
.field private static class [mscorlib]System.Threading.ThreadStart 'CS$<>9__CachedAnonymousMethodDelegate35' .field private static class [mscorlib]System.Threading.ThreadStart 'CS$<>9__CachedAnonymousMethodDelegate35'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig instance class [mscorlib]System.Action .method public hidebysig instance class [mscorlib]System.Action
@ -478,6 +586,69 @@
IL_0023: ret IL_0023: ret
} // end of method InstanceTests::Bug955 } // end of method InstanceTests::Bug955
.method public hidebysig instance void
Bug951(int32 amount) cil managed
{
// Code size 39 (0x27)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38' V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldarg.1
IL_0008: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::amount
IL_000d: ldloc.0
IL_000e: ldarg.0
IL_000f: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<>4__this'
IL_0014: ldarg.0
IL_0015: ldloc.0
IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass38'::'<Bug951>b__36'()
IL_001c: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0021: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0026: ret
} // end of method InstanceTests::Bug951
.method public hidebysig instance void
Bug951b() cil managed
{
// Code size 44 (0x2c)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c' V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldarg.0
IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<>4__this'
IL_000d: ldloc.0
IL_000e: ldarg.0
IL_000f: call instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Foo()
IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::amount
IL_0019: ldarg.0
IL_001a: ldloc.0
IL_001b: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass3c'::'<Bug951b>b__3a'()
IL_0021: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0026: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_002b: ret
} // end of method InstanceTests::Bug951b
.method private hidebysig instance void
DoAction(class [mscorlib]System.Action action) cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method InstanceTests::DoAction
.method private hidebysig instance void
NoOp(int32 a) cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method InstanceTests::NoOp
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

175
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.opt.roslyn.il

@ -31,14 +31,14 @@
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module DelegateConstruction.dll .module DelegateConstruction.dll
// MVID: {732578B7-A105-4FCC-BD88-23E06857F316} // MVID: {7CD915CD-DFC0-4B74-85B2-3BF06B3C53EF}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x013F0000 // Image base: 0x02FE0000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -252,6 +252,114 @@
} // end of class '<>c' } // end of class '<>c'
.class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass8_0'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public int32 amount
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this'
.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 '<>c__DisplayClass8_0'::.ctor
.method assembly hidebysig instance void
'<Bug951>b__0'() cil managed
{
// Code size 40 (0x28)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::amount
IL_0006: ldc.i4.0
IL_0007: bge.s IL_0010
IL_0009: ldarg.0
IL_000a: ldc.i4.0
IL_000b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::amount
IL_0010: ldarg.0
IL_0011: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<>4__this'
IL_0016: ldarg.0
IL_0017: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<Bug951>b__1'()
IL_001d: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0022: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0027: ret
} // end of method '<>c__DisplayClass8_0'::'<Bug951>b__0'
.method assembly hidebysig instance void
'<Bug951>b__1'() cil managed
{
// Code size 18 (0x12)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<>4__this'
IL_0006: ldarg.0
IL_0007: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::amount
IL_000c: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::NoOp(int32)
IL_0011: ret
} // end of method '<>c__DisplayClass8_0'::'<Bug951>b__1'
} // end of class '<>c__DisplayClass8_0'
.class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass9_0'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public int32 amount
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this'
.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 '<>c__DisplayClass9_0'::.ctor
.method assembly hidebysig instance void
'<Bug951b>b__0'() cil managed
{
// Code size 40 (0x28)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::amount
IL_0006: ldc.i4.0
IL_0007: bge.s IL_0010
IL_0009: ldarg.0
IL_000a: ldc.i4.0
IL_000b: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::amount
IL_0010: ldarg.0
IL_0011: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<>4__this'
IL_0016: ldarg.0
IL_0017: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<Bug951b>b__1'()
IL_001d: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0022: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0027: ret
} // end of method '<>c__DisplayClass9_0'::'<Bug951b>b__0'
.method assembly hidebysig instance void
'<Bug951b>b__1'() cil managed
{
// Code size 18 (0x12)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<>4__this'
IL_0006: ldarg.0
IL_0007: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::amount
IL_000c: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::NoOp(int32)
IL_0011: ret
} // end of method '<>c__DisplayClass9_0'::'<Bug951b>b__1'
} // end of class '<>c__DisplayClass9_0'
.method public hidebysig instance class [mscorlib]System.Action .method public hidebysig instance class [mscorlib]System.Action
CaptureOfThis() cil managed CaptureOfThis() cil managed
{ {
@ -495,6 +603,69 @@
IL_0025: ret IL_0025: ret
} // end of method InstanceTests::Bug955 } // end of method InstanceTests::Bug955
.method public hidebysig instance void
Bug951(int32 amount) cil managed
{
// Code size 39 (0x27)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0' V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldarg.0
IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<>4__this'
IL_000d: ldloc.0
IL_000e: ldarg.1
IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::amount
IL_0014: ldarg.0
IL_0015: ldloc.0
IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<Bug951>b__0'()
IL_001c: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0021: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0026: ret
} // end of method InstanceTests::Bug951
.method public hidebysig instance void
Bug951b() cil managed
{
// Code size 44 (0x2c)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0' V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldarg.0
IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<>4__this'
IL_000d: ldloc.0
IL_000e: ldarg.0
IL_000f: call instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Foo()
IL_0014: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::amount
IL_0019: ldarg.0
IL_001a: ldloc.0
IL_001b: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<Bug951b>b__0'()
IL_0021: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0026: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_002b: ret
} // end of method InstanceTests::Bug951b
.method private hidebysig instance void
DoAction(class [mscorlib]System.Action action) cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method InstanceTests::DoAction
.method private hidebysig instance void
NoOp(int32 a) cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method InstanceTests::NoOp
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

203
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.roslyn.il

@ -31,14 +31,14 @@
.ver 0:0:0:0 .ver 0:0:0:0
} }
.module DelegateConstruction.dll .module DelegateConstruction.dll
// MVID: {CAEDF2ED-ABA8-46FA-95A9-59299B362410} // MVID: {FB18F278-AE87-4B57-9460-E08BF17BCEAB}
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
.imagebase 0x10000000 .imagebase 0x10000000
.file alignment 0x00000200 .file alignment 0x00000200
.stackreserve 0x00100000 .stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI .subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY .corflags 0x00000001 // ILONLY
// Image base: 0x01390000 // Image base: 0x01630000
// =============== CLASS MEMBERS DECLARATION =================== // =============== CLASS MEMBERS DECLARATION ===================
@ -263,6 +263,136 @@
} // end of class '<>c' } // end of class '<>c'
.class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass8_0'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public int32 amount
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this'
.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 '<>c__DisplayClass8_0'::.ctor
.method assembly hidebysig instance void
'<Bug951>b__0'() cil managed
{
// Code size 48 (0x30)
.maxstack 3
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::amount
IL_0007: ldc.i4.0
IL_0008: clt
IL_000a: stloc.0
IL_000b: ldloc.0
IL_000c: brfalse.s IL_0017
IL_000e: nop
IL_000f: ldarg.0
IL_0010: ldc.i4.0
IL_0011: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::amount
IL_0016: nop
IL_0017: ldarg.0
IL_0018: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<>4__this'
IL_001d: ldarg.0
IL_001e: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<Bug951>b__1'()
IL_0024: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0029: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_002e: nop
IL_002f: ret
} // end of method '<>c__DisplayClass8_0'::'<Bug951>b__0'
.method assembly hidebysig instance void
'<Bug951>b__1'() cil managed
{
// Code size 20 (0x14)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<>4__this'
IL_0007: ldarg.0
IL_0008: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::amount
IL_000d: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::NoOp(int32)
IL_0012: nop
IL_0013: ret
} // end of method '<>c__DisplayClass8_0'::'<Bug951>b__1'
} // end of class '<>c__DisplayClass8_0'
.class auto ansi sealed nested private beforefieldinit '<>c__DisplayClass9_0'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public int32 amount
.field public class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests '<>4__this'
.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 '<>c__DisplayClass9_0'::.ctor
.method assembly hidebysig instance void
'<Bug951b>b__0'() cil managed
{
// Code size 48 (0x30)
.maxstack 3
.locals init (bool V_0)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::amount
IL_0007: ldc.i4.0
IL_0008: clt
IL_000a: stloc.0
IL_000b: ldloc.0
IL_000c: brfalse.s IL_0017
IL_000e: nop
IL_000f: ldarg.0
IL_0010: ldc.i4.0
IL_0011: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::amount
IL_0016: nop
IL_0017: ldarg.0
IL_0018: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<>4__this'
IL_001d: ldarg.0
IL_001e: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<Bug951b>b__1'()
IL_0024: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0029: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_002e: nop
IL_002f: ret
} // end of method '<>c__DisplayClass9_0'::'<Bug951b>b__0'
.method assembly hidebysig instance void
'<Bug951b>b__1'() cil managed
{
// Code size 20 (0x14)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<>4__this'
IL_0007: ldarg.0
IL_0008: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::amount
IL_000d: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::NoOp(int32)
IL_0012: nop
IL_0013: ret
} // end of method '<>c__DisplayClass9_0'::'<Bug951b>b__1'
} // end of class '<>c__DisplayClass9_0'
.method public hidebysig instance class [mscorlib]System.Action .method public hidebysig instance class [mscorlib]System.Action
CaptureOfThis() cil managed CaptureOfThis() cil managed
{ {
@ -559,6 +689,75 @@
IL_0026: ret IL_0026: ret
} // end of method InstanceTests::Bug955 } // end of method InstanceTests::Bug955
.method public hidebysig instance void
Bug951(int32 amount) cil managed
{
// Code size 41 (0x29)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0' V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldarg.0
IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<>4__this'
IL_000d: ldloc.0
IL_000e: ldarg.1
IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::amount
IL_0014: nop
IL_0015: ldarg.0
IL_0016: ldloc.0
IL_0017: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass8_0'::'<Bug951>b__0'()
IL_001d: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0022: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_0027: nop
IL_0028: ret
} // end of method InstanceTests::Bug951
.method public hidebysig instance void
Bug951b() cil managed
{
// Code size 46 (0x2e)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0' V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldarg.0
IL_0008: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<>4__this'
IL_000d: nop
IL_000e: ldloc.0
IL_000f: ldarg.0
IL_0010: call instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::Foo()
IL_0015: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::amount
IL_001a: ldarg.0
IL_001b: ldloc.0
IL_001c: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests/'<>c__DisplayClass9_0'::'<Bug951b>b__0'()
IL_0022: newobj instance void [mscorlib]System.Action::.ctor(object,
native int)
IL_0027: call instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.DelegateConstruction/InstanceTests::DoAction(class [mscorlib]System.Action)
IL_002c: nop
IL_002d: ret
} // end of method InstanceTests::Bug951b
.method private hidebysig instance void
DoAction(class [mscorlib]System.Action action) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method InstanceTests::DoAction
.method private hidebysig instance void
NoOp(int32 a) cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method InstanceTests::NoOp
.method public hidebysig specialname rtspecialname .method public hidebysig specialname rtspecialname
instance void .ctor() cil managed instance void .ctor() cil managed
{ {

10
ICSharpCode.Decompiler/IL/Transforms/DelegateConstruction.cs

@ -37,6 +37,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
this.decompilationContext = new SimpleTypeResolveContext(function.Method); this.decompilationContext = new SimpleTypeResolveContext(function.Method);
var orphanedVariableInits = new List<ILInstruction>(); var orphanedVariableInits = new List<ILInstruction>();
var targetsToReplace = new List<IInstructionWithVariableOperand>(); var targetsToReplace = new List<IInstructionWithVariableOperand>();
var translatedDisplayClasses = new HashSet<ITypeDefinition>();
foreach (var block in function.Descendants.OfType<Block>()) { foreach (var block in function.Descendants.OfType<Block>()) {
for (int i = block.Instructions.Count - 1; i >= 0; i--) { for (int i = block.Instructions.Count - 1; i >= 0; i--) {
context.CancellationToken.ThrowIfCancellationRequested(); context.CancellationToken.ThrowIfCancellationRequested();
@ -58,12 +59,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (newObj != null && IsInSimpleDisplayClass(newObj.Method)) { if (newObj != null && IsInSimpleDisplayClass(newObj.Method)) {
targetVariable.CaptureScope = FindBlockContainer(block); targetVariable.CaptureScope = FindBlockContainer(block);
targetsToReplace.Add((IInstructionWithVariableOperand)block.Instructions[i]); targetsToReplace.Add((IInstructionWithVariableOperand)block.Instructions[i]);
translatedDisplayClasses.Add(newObj.Method.DeclaringTypeDefinition);
} }
} }
} }
} }
foreach (var target in targetsToReplace.OrderByDescending(t => ((ILInstruction)t).ILRange.Start)) { foreach (var target in targetsToReplace.OrderByDescending(t => ((ILInstruction)t).ILRange.Start)) {
function.AcceptVisitor(new TransformDisplayClassUsages(function, target, target.Variable.CaptureScope, orphanedVariableInits)); function.AcceptVisitor(new TransformDisplayClassUsages(function, target, target.Variable.CaptureScope, orphanedVariableInits, translatedDisplayClasses));
} }
foreach (var store in orphanedVariableInits) { foreach (var store in orphanedVariableInits) {
if (store.Parent is Block containingBlock) if (store.Parent is Block containingBlock)
@ -216,6 +218,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
readonly IInstructionWithVariableOperand targetLoad; readonly IInstructionWithVariableOperand targetLoad;
readonly List<ILVariable> targetAndCopies = new List<ILVariable>(); readonly List<ILVariable> targetAndCopies = new List<ILVariable>();
readonly List<ILInstruction> orphanedVariableInits; readonly List<ILInstruction> orphanedVariableInits;
readonly HashSet<ITypeDefinition> translatedDisplayClasses;
readonly Dictionary<IField, DisplayClassVariable> initValues = new Dictionary<IField, DisplayClassVariable>(); readonly Dictionary<IField, DisplayClassVariable> initValues = new Dictionary<IField, DisplayClassVariable>();
struct DisplayClassVariable struct DisplayClassVariable
@ -224,12 +227,13 @@ namespace ICSharpCode.Decompiler.IL.Transforms
public ILInstruction value; public ILInstruction value;
} }
public TransformDisplayClassUsages(ILFunction function, IInstructionWithVariableOperand targetLoad, BlockContainer captureScope, List<ILInstruction> orphanedVariableInits) public TransformDisplayClassUsages(ILFunction function, IInstructionWithVariableOperand targetLoad, BlockContainer captureScope, List<ILInstruction> orphanedVariableInits, HashSet<ITypeDefinition> translatedDisplayClasses)
{ {
this.currentFunction = function; this.currentFunction = function;
this.targetLoad = targetLoad; this.targetLoad = targetLoad;
this.captureScope = captureScope; this.captureScope = captureScope;
this.orphanedVariableInits = orphanedVariableInits; this.orphanedVariableInits = orphanedVariableInits;
this.translatedDisplayClasses = translatedDisplayClasses;
this.targetAndCopies.Add(targetLoad.Variable); this.targetAndCopies.Add(targetLoad.Variable);
} }
@ -271,6 +275,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
orphanedVariableInits.Add(inst); orphanedVariableInits.Add(inst);
value = inst.Value; value = inst.Value;
} else { } else {
if (!translatedDisplayClasses.Contains(field.DeclaringTypeDefinition))
return;
v = currentFunction.RegisterVariable(VariableKind.Local, field.Type, field.Name); v = currentFunction.RegisterVariable(VariableKind.Local, field.Type, field.Name);
v.CaptureScope = captureScope; v.CaptureScope = captureScope;
inst.ReplaceWith(new StLoc(v, inst.Value)); inst.ReplaceWith(new StLoc(v, inst.Value));

Loading…
Cancel
Save