Skip to content

Commit 0357c81

Browse files
committed
Move stackalloc tests to pretty-tests.
1 parent f4682fd commit 0357c81

File tree

6 files changed

+457
-35
lines changed

6 files changed

+457
-35
lines changed

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,6 @@ public unsafe void FixMultipleStrings(string text)
5959
}
6060
}
6161

62-
public unsafe string UsePointer(double* ptr)
63-
{
64-
return ptr->ToString();
65-
}
66-
67-
public unsafe string StackAlloc(int count)
68-
{
69-
char* ptr = stackalloc char[count];
70-
char* ptr2 = stackalloc char[100];
71-
for (int i = 0; i < count; i++) {
72-
ptr[i] = (char)i;
73-
ptr2[i] = '\0';
74-
}
75-
return this.UsePointer((double*)ptr);
76-
}
77-
78-
public unsafe string StackAllocStruct(int count)
79-
{
80-
SimpleStruct* s = stackalloc SimpleStruct[checked(count * 2)];
81-
SimpleStruct* _ = stackalloc SimpleStruct[10];
82-
return this.UsePointer(&s->Y);
83-
}
84-
8562
public unsafe byte* PointerArithmetic2(long* p, int y, int x)
8663
{
8764
return (byte*)((short*)p + (y * x));

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,29 @@ public unsafe double FixedMemberAccess(StructWithFixedSizeMembers* m, int i)
257257
return m->Doubles;
258258
}
259259

260+
public unsafe string UsePointer(double* ptr)
261+
{
262+
return ptr->ToString();
263+
}
264+
265+
public unsafe string StackAlloc(int count)
266+
{
267+
char* ptr = stackalloc char[count];
268+
char* ptr2 = stackalloc char[100];
269+
for (int i = 0; i < count; i++) {
270+
ptr[i] = (char)i;
271+
ptr2[i] = '\0';
272+
}
273+
return this.UsePointer((double*)ptr);
274+
}
275+
276+
public unsafe string StackAllocStruct(int count)
277+
{
278+
SimpleStruct* ptr = stackalloc SimpleStruct[checked(count * 2)];
279+
SimpleStruct* _ = stackalloc SimpleStruct[10];
280+
return this.UsePointer(&ptr->Y);
281+
}
282+
260283
unsafe ~UnsafeCode()
261284
{
262285
this.PassPointerAsRefParameter(this.NullPointer);

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

Lines changed: 122 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
1111
.ver 4:0:0:0
1212
}
13-
.assembly '4mqlts3y'
13+
.assembly '5ph04scr'
1414
{
1515
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
1616
.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 @@
2020
.hash algorithm 0x00008004
2121
.ver 0:0:0:0
2222
}
23-
.module '4mqlts3y.dll'
24-
// MVID: {5733C4E7-C3DA-4F38-A641-CE223719D7AA}
23+
.module '5ph04scr.dll'
24+
// MVID: {979A8D45-AB93-4029-8820-2753F73AD209}
2525
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
2626
.imagebase 0x10000000
2727
.file alignment 0x00000200
2828
.stackreserve 0x00100000
2929
.subsystem 0x0003 // WINDOWS_CUI
3030
.corflags 0x00000001 // ILONLY
31-
// Image base: 0x01000000
31+
// Image base: 0x01AF0000
3232

3333

3434
// =============== CLASS MEMBERS DECLARATION ===================
@@ -980,6 +980,124 @@
980980
IL_0011: ret
981981
} // end of method UnsafeCode::FixedMemberBasePointer
982982

983+
.method public hidebysig instance string
984+
UsePointer(float64* ptr) cil managed
985+
{
986+
// Code size 12 (0xc)
987+
.maxstack 1
988+
.locals init (string V_0)
989+
IL_0000: nop
990+
IL_0001: ldarg.1
991+
IL_0002: call instance string [mscorlib]System.Double::ToString()
992+
IL_0007: stloc.0
993+
IL_0008: br.s IL_000a
994+
995+
IL_000a: ldloc.0
996+
IL_000b: ret
997+
} // end of method UnsafeCode::UsePointer
998+
999+
.method public hidebysig instance string
1000+
StackAlloc(int32 count) cil managed
1001+
{
1002+
// Code size 65 (0x41)
1003+
.maxstack 3
1004+
.locals init (char* V_0,
1005+
char* V_1,
1006+
int32 V_2,
1007+
string V_3,
1008+
bool V_4)
1009+
IL_0000: nop
1010+
IL_0001: ldarg.1
1011+
IL_0002: conv.u
1012+
IL_0003: ldc.i4.2
1013+
IL_0004: mul.ovf.un
1014+
IL_0005: localloc
1015+
IL_0007: stloc.0
1016+
IL_0008: ldc.i4.s 100
1017+
IL_000a: conv.u
1018+
IL_000b: ldc.i4.2
1019+
IL_000c: mul.ovf.un
1020+
IL_000d: localloc
1021+
IL_000f: stloc.1
1022+
IL_0010: ldc.i4.0
1023+
IL_0011: stloc.2
1024+
IL_0012: br.s IL_002b
1025+
1026+
IL_0014: nop
1027+
IL_0015: ldloc.0
1028+
IL_0016: ldloc.2
1029+
IL_0017: conv.i
1030+
IL_0018: ldc.i4.2
1031+
IL_0019: mul
1032+
IL_001a: add
1033+
IL_001b: ldloc.2
1034+
IL_001c: conv.u2
1035+
IL_001d: stind.i2
1036+
IL_001e: ldloc.1
1037+
IL_001f: ldloc.2
1038+
IL_0020: conv.i
1039+
IL_0021: ldc.i4.2
1040+
IL_0022: mul
1041+
IL_0023: add
1042+
IL_0024: ldc.i4.0
1043+
IL_0025: stind.i2
1044+
IL_0026: nop
1045+
IL_0027: ldloc.2
1046+
IL_0028: ldc.i4.1
1047+
IL_0029: add
1048+
IL_002a: stloc.2
1049+
IL_002b: ldloc.2
1050+
IL_002c: ldarg.1
1051+
IL_002d: clt
1052+
IL_002f: stloc.s V_4
1053+
IL_0031: ldloc.s V_4
1054+
IL_0033: brtrue.s IL_0014
1055+
1056+
IL_0035: ldarg.0
1057+
IL_0036: ldloc.0
1058+
IL_0037: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
1059+
IL_003c: stloc.3
1060+
IL_003d: br.s IL_003f
1061+
1062+
IL_003f: ldloc.3
1063+
IL_0040: ret
1064+
} // end of method UnsafeCode::StackAlloc
1065+
1066+
.method public hidebysig instance string
1067+
StackAllocStruct(int32 count) cil managed
1068+
{
1069+
// Code size 46 (0x2e)
1070+
.maxstack 2
1071+
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct* V_0,
1072+
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct* V_1,
1073+
string V_2)
1074+
IL_0000: nop
1075+
IL_0001: ldarg.1
1076+
IL_0002: ldc.i4.2
1077+
IL_0003: mul.ovf
1078+
IL_0004: conv.u
1079+
IL_0005: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
1080+
IL_000b: mul.ovf.un
1081+
IL_000c: localloc
1082+
IL_000e: stloc.0
1083+
IL_000f: ldc.i4.s 10
1084+
IL_0011: conv.u
1085+
IL_0012: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
1086+
IL_0018: mul.ovf.un
1087+
IL_0019: localloc
1088+
IL_001b: stloc.1
1089+
IL_001c: ldarg.0
1090+
IL_001d: ldloc.0
1091+
IL_001e: ldflda float64 ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct::Y
1092+
IL_0023: conv.u
1093+
IL_0024: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
1094+
IL_0029: stloc.2
1095+
IL_002a: br.s IL_002c
1096+
1097+
IL_002c: ldloc.2
1098+
IL_002d: ret
1099+
} // end of method UnsafeCode::StackAllocStruct
1100+
9831101
.method family hidebysig virtual instance void
9841102
Finalize() cil managed
9851103
{

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

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
1111
.ver 4:0:0:0
1212
}
13-
.assembly '4wfrzmwx'
13+
.assembly zuwavv1x
1414
{
1515
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
1616
.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 @@
2020
.hash algorithm 0x00008004
2121
.ver 0:0:0:0
2222
}
23-
.module '4wfrzmwx.dll'
24-
// MVID: {1CBCDACC-05B6-4B2D-BF36-5845CD657180}
23+
.module zuwavv1x.dll
24+
// MVID: {4CC9FC6C-21CA-408A-ABC9-544A07D1E512}
2525
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
2626
.imagebase 0x10000000
2727
.file alignment 0x00000200
2828
.stackreserve 0x00100000
2929
.subsystem 0x0003 // WINDOWS_CUI
3030
.corflags 0x00000001 // ILONLY
31-
// Image base: 0x00520000
31+
// Image base: 0x01600000
3232

3333

3434
// =============== CLASS MEMBERS DECLARATION ===================
@@ -765,6 +765,99 @@
765765
IL_000c: ret
766766
} // end of method UnsafeCode::FixedMemberBasePointer
767767

768+
.method public hidebysig instance string
769+
UsePointer(float64* ptr) cil managed
770+
{
771+
// Code size 7 (0x7)
772+
.maxstack 8
773+
IL_0000: ldarg.1
774+
IL_0001: call instance string [mscorlib]System.Double::ToString()
775+
IL_0006: ret
776+
} // end of method UnsafeCode::UsePointer
777+
778+
.method public hidebysig instance string
779+
StackAlloc(int32 count) cil managed
780+
{
781+
// Code size 52 (0x34)
782+
.maxstack 3
783+
.locals init (char* V_0,
784+
char* V_1,
785+
int32 V_2)
786+
IL_0000: ldarg.1
787+
IL_0001: conv.u
788+
IL_0002: ldc.i4.2
789+
IL_0003: mul.ovf.un
790+
IL_0004: localloc
791+
IL_0006: stloc.0
792+
IL_0007: ldc.i4.s 100
793+
IL_0009: conv.u
794+
IL_000a: ldc.i4.2
795+
IL_000b: mul.ovf.un
796+
IL_000c: localloc
797+
IL_000e: stloc.1
798+
IL_000f: ldc.i4.0
799+
IL_0010: stloc.2
800+
IL_0011: br.s IL_0028
801+
802+
IL_0013: ldloc.0
803+
IL_0014: ldloc.2
804+
IL_0015: conv.i
805+
IL_0016: ldc.i4.2
806+
IL_0017: mul
807+
IL_0018: add
808+
IL_0019: ldloc.2
809+
IL_001a: conv.u2
810+
IL_001b: stind.i2
811+
IL_001c: ldloc.1
812+
IL_001d: ldloc.2
813+
IL_001e: conv.i
814+
IL_001f: ldc.i4.2
815+
IL_0020: mul
816+
IL_0021: add
817+
IL_0022: ldc.i4.0
818+
IL_0023: stind.i2
819+
IL_0024: ldloc.2
820+
IL_0025: ldc.i4.1
821+
IL_0026: add
822+
IL_0027: stloc.2
823+
IL_0028: ldloc.2
824+
IL_0029: ldarg.1
825+
IL_002a: blt.s IL_0013
826+
827+
IL_002c: ldarg.0
828+
IL_002d: ldloc.0
829+
IL_002e: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
830+
IL_0033: ret
831+
} // end of method UnsafeCode::StackAlloc
832+
833+
.method public hidebysig instance string
834+
StackAllocStruct(int32 count) cil managed
835+
{
836+
// Code size 41 (0x29)
837+
.maxstack 2
838+
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct* V_0)
839+
IL_0000: ldarg.1
840+
IL_0001: ldc.i4.2
841+
IL_0002: mul.ovf
842+
IL_0003: conv.u
843+
IL_0004: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
844+
IL_000a: mul.ovf.un
845+
IL_000b: localloc
846+
IL_000d: stloc.0
847+
IL_000e: ldc.i4.s 10
848+
IL_0010: conv.u
849+
IL_0011: sizeof ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct
850+
IL_0017: mul.ovf.un
851+
IL_0018: localloc
852+
IL_001a: pop
853+
IL_001b: ldarg.0
854+
IL_001c: ldloc.0
855+
IL_001d: ldflda float64 ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode/SimpleStruct::Y
856+
IL_0022: conv.u
857+
IL_0023: call instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.UnsafeCode::UsePointer(float64*)
858+
IL_0028: ret
859+
} // end of method UnsafeCode::StackAllocStruct
860+
768861
.method family hidebysig virtual instance void
769862
Finalize() cil managed
770863
{

0 commit comments

Comments
 (0)