Browse Source

Move stackalloc tests to pretty-tests.

pull/924/head
Daniel Grunwald 8 years ago
parent
commit
0357c81c44
  1. 23
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/UnsafeCode.cs
  2. 23
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs
  3. 126
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.il
  4. 101
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.opt.il
  5. 97
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.opt.roslyn.il
  6. 122
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.roslyn.il

23
ICSharpCode.Decompiler.Tests/TestCases/Correctness/UnsafeCode.cs

@ -59,29 +59,6 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -59,29 +59,6 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
}
public unsafe string UsePointer(double* ptr)
{
return ptr->ToString();
}
public unsafe string StackAlloc(int count)
{
char* ptr = stackalloc char[count];
char* ptr2 = stackalloc char[100];
for (int i = 0; i < count; i++) {
ptr[i] = (char)i;
ptr2[i] = '\0';
}
return this.UsePointer((double*)ptr);
}
public unsafe string StackAllocStruct(int count)
{
SimpleStruct* s = stackalloc SimpleStruct[checked(count * 2)];
SimpleStruct* _ = stackalloc SimpleStruct[10];
return this.UsePointer(&s->Y);
}
public unsafe byte* PointerArithmetic2(long* p, int y, int x)
{
return (byte*)((short*)p + (y * x));

23
ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs

@ -257,6 +257,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -257,6 +257,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return m->Doubles;
}
public unsafe string UsePointer(double* ptr)
{
return ptr->ToString();
}
public unsafe string StackAlloc(int count)
{
char* ptr = stackalloc char[count];
char* ptr2 = stackalloc char[100];
for (int i = 0; i < count; i++) {
ptr[i] = (char)i;
ptr2[i] = '\0';
}
return this.UsePointer((double*)ptr);
}
public unsafe string StackAllocStruct(int count)
{
SimpleStruct* ptr = stackalloc SimpleStruct[checked(count * 2)];
SimpleStruct* _ = stackalloc SimpleStruct[10];
return this.UsePointer(&ptr->Y);
}
unsafe ~UnsafeCode()
{
this.PassPointerAsRefParameter(this.NullPointer);

126
ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.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 '4mqlts3y'
.assembly '5ph04scr'
{
.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 '4mqlts3y.dll'
// MVID: {5733C4E7-C3DA-4F38-A641-CE223719D7AA}
.module '5ph04scr.dll'
// MVID: {979A8D45-AB93-4029-8820-2753F73AD209}
.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: 0x01000000
// Image base: 0x01AF0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -980,6 +980,124 @@ @@ -980,6 +980,124 @@
IL_0011: ret
} // end of method UnsafeCode::FixedMemberBasePointer
.method public hidebysig instance string
UsePointer(float64* ptr) cil managed
{
// Code size 12 (0xc)
.maxstack 1
.locals init (string V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: call instance string [mscorlib]System.Double::ToString()
IL_0007: stloc.0
IL_0008: br.s IL_000a
IL_000a: ldloc.0
IL_000b: ret
} // end of method UnsafeCode::UsePointer
.method public hidebysig instance string
StackAlloc(int32 count) cil managed
{
// Code size 65 (0x41)
.maxstack 3
.locals init (char* V_0,
char* V_1,
int32 V_2,
string V_3,
bool V_4)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: conv.u
IL_0003: ldc.i4.2
IL_0004: mul.ovf.un
IL_0005: localloc
IL_0007: stloc.0
IL_0008: ldc.i4.s 100
IL_000a: conv.u
IL_000b: ldc.i4.2
IL_000c: mul.ovf.un
IL_000d: localloc
IL_000f: stloc.1
IL_0010: ldc.i4.0
IL_0011: stloc.2
IL_0012: br.s IL_002b
IL_0014: nop
IL_0015: ldloc.0
IL_0016: ldloc.2
IL_0017: conv.i
IL_0018: ldc.i4.2
IL_0019: mul
IL_001a: add
IL_001b: ldloc.2
IL_001c: conv.u2
IL_001d: stind.i2
IL_001e: ldloc.1
IL_001f: ldloc.2
IL_0020: conv.i
IL_0021: ldc.i4.2
IL_0022: mul
IL_0023: add
IL_0024: ldc.i4.0
IL_0025: stind.i2
IL_0026: nop
IL_0027: ldloc.2
IL_0028: ldc.i4.1
IL_0029: add
IL_002a: stloc.2
IL_002b: ldloc.2
IL_002c: ldarg.1
IL_002d: clt
IL_002f: stloc.s V_4
IL_0031: ldloc.s V_4
IL_0033: brtrue.s IL_0014
IL_0035: ldarg.0
IL_0036: ldloc.0
IL_0037: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
IL_003c: stloc.3
IL_003d: br.s IL_003f
IL_003f: ldloc.3
IL_0040: ret
} // end of method UnsafeCode::StackAlloc
.method public hidebysig instance string
StackAllocStruct(int32 count) cil managed
{
// Code size 46 (0x2e)
.maxstack 2
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct* V_0,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct* V_1,
string V_2)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldc.i4.2
IL_0003: mul.ovf
IL_0004: conv.u
IL_0005: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
IL_000b: mul.ovf.un
IL_000c: localloc
IL_000e: stloc.0
IL_000f: ldc.i4.s 10
IL_0011: conv.u
IL_0012: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
IL_0018: mul.ovf.un
IL_0019: localloc
IL_001b: stloc.1
IL_001c: ldarg.0
IL_001d: ldloc.0
IL_001e: ldflda float64 ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct::Y
IL_0023: conv.u
IL_0024: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
IL_0029: stloc.2
IL_002a: br.s IL_002c
IL_002c: ldloc.2
IL_002d: ret
} // end of method UnsafeCode::StackAllocStruct
.method family hidebysig virtual instance void
Finalize() cil managed
{

101
ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.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 '4wfrzmwx'
.assembly zuwavv1x
{
.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 '4wfrzmwx.dll'
// MVID: {1CBCDACC-05B6-4B2D-BF36-5845CD657180}
.module zuwavv1x.dll
// MVID: {4CC9FC6C-21CA-408A-ABC9-544A07D1E512}
.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: 0x00520000
// Image base: 0x01600000
// =============== CLASS MEMBERS DECLARATION ===================
@ -765,6 +765,99 @@ @@ -765,6 +765,99 @@
IL_000c: ret
} // end of method UnsafeCode::FixedMemberBasePointer
.method public hidebysig instance string
UsePointer(float64* ptr) cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.1
IL_0001: call instance string [mscorlib]System.Double::ToString()
IL_0006: ret
} // end of method UnsafeCode::UsePointer
.method public hidebysig instance string
StackAlloc(int32 count) cil managed
{
// Code size 52 (0x34)
.maxstack 3
.locals init (char* V_0,
char* V_1,
int32 V_2)
IL_0000: ldarg.1
IL_0001: conv.u
IL_0002: ldc.i4.2
IL_0003: mul.ovf.un
IL_0004: localloc
IL_0006: stloc.0
IL_0007: ldc.i4.s 100
IL_0009: conv.u
IL_000a: ldc.i4.2
IL_000b: mul.ovf.un
IL_000c: localloc
IL_000e: stloc.1
IL_000f: ldc.i4.0
IL_0010: stloc.2
IL_0011: br.s IL_0028
IL_0013: ldloc.0
IL_0014: ldloc.2
IL_0015: conv.i
IL_0016: ldc.i4.2
IL_0017: mul
IL_0018: add
IL_0019: ldloc.2
IL_001a: conv.u2
IL_001b: stind.i2
IL_001c: ldloc.1
IL_001d: ldloc.2
IL_001e: conv.i
IL_001f: ldc.i4.2
IL_0020: mul
IL_0021: add
IL_0022: ldc.i4.0
IL_0023: stind.i2
IL_0024: ldloc.2
IL_0025: ldc.i4.1
IL_0026: add
IL_0027: stloc.2
IL_0028: ldloc.2
IL_0029: ldarg.1
IL_002a: blt.s IL_0013
IL_002c: ldarg.0
IL_002d: ldloc.0
IL_002e: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
IL_0033: ret
} // end of method UnsafeCode::StackAlloc
.method public hidebysig instance string
StackAllocStruct(int32 count) cil managed
{
// Code size 41 (0x29)
.maxstack 2
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct* V_0)
IL_0000: ldarg.1
IL_0001: ldc.i4.2
IL_0002: mul.ovf
IL_0003: conv.u
IL_0004: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
IL_000a: mul.ovf.un
IL_000b: localloc
IL_000d: stloc.0
IL_000e: ldc.i4.s 10
IL_0010: conv.u
IL_0011: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
IL_0017: mul.ovf.un
IL_0018: localloc
IL_001a: pop
IL_001b: ldarg.0
IL_001c: ldloc.0
IL_001d: ldflda float64 ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct::Y
IL_0022: conv.u
IL_0023: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
IL_0028: ret
} // end of method UnsafeCode::StackAllocStruct
.method family hidebysig virtual instance void
Finalize() cil managed
{

97
ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.opt.roslyn.il

@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module UnsafeCode.dll
// MVID: {C46FA0A4-EE31-4A04-9894-41AA162DD602}
// MVID: {958D637E-F39D-447B-A248-B73AECEC847A}
.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: 0x00DE0000
// Image base: 0x007C0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -771,6 +771,99 @@ @@ -771,6 +771,99 @@
IL_000c: ret
} // end of method UnsafeCode::FixedMemberBasePointer
.method public hidebysig instance string
UsePointer(float64* ptr) cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.1
IL_0001: call instance string [mscorlib]System.Double::ToString()
IL_0006: ret
} // end of method UnsafeCode::UsePointer
.method public hidebysig instance string
StackAlloc(int32 count) cil managed
{
// Code size 52 (0x34)
.maxstack 3
.locals init (char* V_0,
char* V_1,
int32 V_2)
IL_0000: ldarg.1
IL_0001: conv.u
IL_0002: ldc.i4.2
IL_0003: mul.ovf.un
IL_0004: localloc
IL_0006: stloc.0
IL_0007: ldc.i4.s 100
IL_0009: conv.u
IL_000a: ldc.i4.2
IL_000b: mul.ovf.un
IL_000c: localloc
IL_000e: stloc.1
IL_000f: ldc.i4.0
IL_0010: stloc.2
IL_0011: br.s IL_0028
IL_0013: ldloc.0
IL_0014: ldloc.2
IL_0015: conv.i
IL_0016: ldc.i4.2
IL_0017: mul
IL_0018: add
IL_0019: ldloc.2
IL_001a: conv.u2
IL_001b: stind.i2
IL_001c: ldloc.1
IL_001d: ldloc.2
IL_001e: conv.i
IL_001f: ldc.i4.2
IL_0020: mul
IL_0021: add
IL_0022: ldc.i4.0
IL_0023: stind.i2
IL_0024: ldloc.2
IL_0025: ldc.i4.1
IL_0026: add
IL_0027: stloc.2
IL_0028: ldloc.2
IL_0029: ldarg.1
IL_002a: blt.s IL_0013
IL_002c: ldarg.0
IL_002d: ldloc.0
IL_002e: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
IL_0033: ret
} // end of method UnsafeCode::StackAlloc
.method public hidebysig instance string
StackAllocStruct(int32 count) cil managed
{
// Code size 41 (0x29)
.maxstack 2
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct* V_0)
IL_0000: ldarg.1
IL_0001: ldc.i4.2
IL_0002: mul.ovf
IL_0003: conv.u
IL_0004: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
IL_000a: mul.ovf.un
IL_000b: localloc
IL_000d: stloc.0
IL_000e: ldc.i4.s 10
IL_0010: conv.u
IL_0011: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
IL_0017: mul.ovf.un
IL_0018: localloc
IL_001a: pop
IL_001b: ldarg.0
IL_001c: ldloc.0
IL_001d: ldflda float64 ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct::Y
IL_0022: conv.u
IL_0023: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
IL_0028: ret
} // end of method UnsafeCode::StackAllocStruct
.method family hidebysig virtual instance void
Finalize() cil managed
{

122
ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.roslyn.il

@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
.ver 0:0:0:0
}
.module UnsafeCode.dll
// MVID: {A389E3D9-8350-4463-A41E-65C50B6E19ED}
// MVID: {A3E96E65-04A9-4270-81A4-F0FB3CB8D517}
.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: 0x01620000
// Image base: 0x01310000
// =============== CLASS MEMBERS DECLARATION ===================
@ -986,6 +986,124 @@ @@ -986,6 +986,124 @@
IL_0011: ret
} // end of method UnsafeCode::FixedMemberBasePointer
.method public hidebysig instance string
UsePointer(float64* ptr) cil managed
{
// Code size 12 (0xc)
.maxstack 1
.locals init (string V_0)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: call instance string [mscorlib]System.Double::ToString()
IL_0007: stloc.0
IL_0008: br.s IL_000a
IL_000a: ldloc.0
IL_000b: ret
} // end of method UnsafeCode::UsePointer
.method public hidebysig instance string
StackAlloc(int32 count) cil managed
{
// Code size 65 (0x41)
.maxstack 3
.locals init (char* V_0,
char* V_1,
int32 V_2,
bool V_3,
string V_4)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: conv.u
IL_0003: ldc.i4.2
IL_0004: mul.ovf.un
IL_0005: localloc
IL_0007: stloc.0
IL_0008: ldc.i4.s 100
IL_000a: conv.u
IL_000b: ldc.i4.2
IL_000c: mul.ovf.un
IL_000d: localloc
IL_000f: stloc.1
IL_0010: ldc.i4.0
IL_0011: stloc.2
IL_0012: br.s IL_002b
IL_0014: nop
IL_0015: ldloc.0
IL_0016: ldloc.2
IL_0017: conv.i
IL_0018: ldc.i4.2
IL_0019: mul
IL_001a: add
IL_001b: ldloc.2
IL_001c: conv.u2
IL_001d: stind.i2
IL_001e: ldloc.1
IL_001f: ldloc.2
IL_0020: conv.i
IL_0021: ldc.i4.2
IL_0022: mul
IL_0023: add
IL_0024: ldc.i4.0
IL_0025: stind.i2
IL_0026: nop
IL_0027: ldloc.2
IL_0028: ldc.i4.1
IL_0029: add
IL_002a: stloc.2
IL_002b: ldloc.2
IL_002c: ldarg.1
IL_002d: clt
IL_002f: stloc.3
IL_0030: ldloc.3
IL_0031: brtrue.s IL_0014
IL_0033: ldarg.0
IL_0034: ldloc.0
IL_0035: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
IL_003a: stloc.s V_4
IL_003c: br.s IL_003e
IL_003e: ldloc.s V_4
IL_0040: ret
} // end of method UnsafeCode::StackAlloc
.method public hidebysig instance string
StackAllocStruct(int32 count) cil managed
{
// Code size 46 (0x2e)
.maxstack 2
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct* V_0,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct* V_1,
string V_2)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldc.i4.2
IL_0003: mul.ovf
IL_0004: conv.u
IL_0005: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
IL_000b: mul.ovf.un
IL_000c: localloc
IL_000e: stloc.0
IL_000f: ldc.i4.s 10
IL_0011: conv.u
IL_0012: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
IL_0018: mul.ovf.un
IL_0019: localloc
IL_001b: stloc.1
IL_001c: ldarg.0
IL_001d: ldloc.0
IL_001e: ldflda float64 ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct::Y
IL_0023: conv.u
IL_0024: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
IL_0029: stloc.2
IL_002a: br.s IL_002c
IL_002c: ldloc.2
IL_002d: ret
} // end of method UnsafeCode::StackAllocStruct
.method family hidebysig virtual instance void
Finalize() cil managed
{

Loading…
Cancel
Save