3 using System
.Reflection
;
4 using System
.Collections
.Generic
;
5 using System
.Runtime
.InteropServices
;
6 using System
.Runtime
.CompilerServices
;
9 * Regression tests for the mono JIT.
11 * Each test needs to be of the form:
13 * static int test_<result>_<name> ();
15 * where <result> is an integer (the value that needs to be returned by
16 * the method to make it pass.
17 * <name> is a user-displayed name used to identify the test.
19 * The tests can be driven in two ways:
20 * *) running the program directly: Main() uses reflection to find and invoke
21 * the test methods (this is useful mostly to check that the tests are correct)
22 * *) with the --regression switch of the jit (this is the preferred way since
23 * all the tests will be run with optimizations on and off)
25 * The reflection logic could be moved to a .dll since we need at least another
26 * regression test file written in IL code to have better control on how
65 public void populate ()
75 return one
== 1 && two
== 2 &&
76 three
== 3 && four
== 4 &&
77 five
== 5 && six
== 6 &&
78 seven
== 7 && eight
== 8 &&
79 nine
== 9 && ten
== 10;
85 public Sample (int v
) {
90 [StructLayout ( LayoutKind
.Explicit
)]
91 struct StructWithBigOffsets
{
92 [ FieldOffset(10000) ] public byte b
;
93 [ FieldOffset(10001) ] public sbyte sb
;
94 [ FieldOffset(11000) ] public short s
;
95 [ FieldOffset(11002) ] public ushort us
;
96 [ FieldOffset(12000) ] public uint i
;
97 [ FieldOffset(12004) ] public int si
;
98 [ FieldOffset(13000) ] public long l
;
99 [ FieldOffset(14000) ] public float f
;
100 [ FieldOffset(15000) ] public double d
;
110 public long a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
,l
,m
,n
,o
,p
,q
,r
,s
,t
,u
,v
;
114 public Alpha a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
,l
,m
,n
,o
,p
,q
,r
,s
,t
,u
,v
;
118 public Beta a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
,l
,m
,n
,o
,p
,q
,r
,s
,t
,u
,v
;
124 public static int Main (string[] args
) {
125 return TestDriver
.RunTests (typeof (Tests
), args
);
129 public static int test_0_return () {
133 s
.c
= (short)(s
.a
+ s
.b
);
138 public static int test_0_string_access () {
145 public static int test_0_string_virtual_call () {
147 string s2
= s
.ToString ();
153 public static int test_0_iface_call () {
155 object o
= ((ICloneable
)s
).Clone ();
159 public static int test_5_newobj () {
160 Sample s
= new Sample (5);
164 public static int test_4_box () {
169 public static int test_0_enum_unbox () {
170 SampleEnum x
= SampleEnum
.A
;
180 static Simple
get_simple (int v
) {
181 Simple r
= new Simple ();
184 r
.c
= (short)(v
+ 2);
190 public static int test_3_return_struct () {
191 Simple v
= get_simple (1);
204 public virtual Simple
v_get_simple (int v
)
206 return get_simple (v
);
209 public static int test_2_return_struct_virtual () {
210 Tests t
= new Tests ();
211 Simple v
= t
.v_get_simple (2);
224 static int receive_simple (int a
, Simple v
, int b
) {
240 public static int test_5_pass_struct () {
241 Simple v
= get_simple (1);
242 if (receive_simple (7, v
, 9) != 0)
244 if (receive_simple (7, get_simple (1), 9) != 0)
250 public static int test_5_pass_static_struct () {
251 s_v
= get_simple (1);
252 if (receive_simple (7, s_v
, 9) != 0)
257 // Test alignment of small structs
259 static Small
get_small (byte v
) {
260 Small r
= new Small ();
263 r
.b2
= (byte)(v
+ 1);
268 static Small
return_small (Small s
) {
272 static int receive_small (int a
, Small v
, int b
) {
280 static int receive_small_sparc_many_args (int a
, int a2
, int a3
, int a4
, int a5
, int a6
, Small v
, int b
) {
288 public static int test_5_pass_small_struct () {
289 Small v
= get_small (1);
290 if (receive_small (7, v
, 9) != 0)
292 if (receive_small (7, get_small (1), 9) != 0)
294 if (receive_small_sparc_many_args (1, 2, 3, 4, 5, 6, v
, 9) != 0)
296 v
= return_small (v
);
304 // 64-bits, 32-bit aligned
310 static int check_struct1(struct1 x
) {
318 static int pass_struct1(int a
, int b
, struct1 x
) {
323 return check_struct1(x
);
326 static int pass_struct1(int a
, struct1 x
) {
329 return check_struct1(x
);
332 static int pass_struct1(struct1 x
) {
333 return check_struct1(x
);
336 public static int test_0_struct1_args () {
342 if ((r
= check_struct1(x
)) != 0)
344 if ((r
= pass_struct1(x
)) != 0)
346 if ((r
= pass_struct1(3, x
)) != 0)
348 if ((r
= pass_struct1(3, 4, x
)) != 0)
353 // 64-bits, 64-bit aligned
358 static int check_struct2(struct2 x
) {
364 static int pass_struct2(int a
, int b
, int c
, struct2 x
) {
371 return check_struct2(x
);
374 static int pass_struct2(int a
, int b
, struct2 x
) {
379 return check_struct2(x
);
382 static int pass_struct2(int a
, struct2 x
) {
385 return check_struct2(x
);
388 static int pass_struct2(struct2 x
) {
389 return check_struct2(x
);
392 public static int test_0_struct2_args () {
397 if ((r
= check_struct2(x
)) != 0)
399 if ((r
= pass_struct2(x
)) != 0)
401 if ((r
= pass_struct2(3, x
)) != 0)
403 if ((r
= pass_struct2(3, 4, x
)) != 0)
405 if ((r
= pass_struct2(3, 4, 5, x
)) != 0)
412 public long i
, j
, k
, l
;
415 static int pass_struct3 (int i
, int j
, int k
, int l
, int m
, int n
, int o
, int p
, Struct3 s
, int q
) {
416 if (s
.i
+ s
.j
+ s
.k
+ s
.l
!= 10)
422 public static int test_0_struct3_args () {
423 Struct3 s
= new Struct3 ();
429 return pass_struct3 (1, 2, 3, 4, 5, 6, 7, 8, s
, 9);
432 // Struct with unaligned size on 64 bit machines
434 public int i
, j
, k
, l
, m
;
435 public int i1
, i2
, i3
, i4
, i5
, i6
;
438 static int pass_struct4 (Struct4 s
) {
439 if (s
.i
+ s
.j
+ s
.k
+ s
.l
+ s
.m
!= 15)
445 public static int test_0_struct4_args () {
446 Struct4 s
= new Struct4 ();
453 return pass_struct4 (s
);
461 public AStruct (int i
) {
465 public override int GetHashCode () {
470 // Test that vtypes are unboxed during a virtual call
471 public static int test_44_unbox_trampoline () {
472 AStruct s
= new AStruct (44);
474 return o
.GetHashCode ();
477 public static int test_0_unbox_trampoline2 () {
481 if (i
.ToString () != "12")
483 if (((Int32
)o
).ToString () != "12")
485 if (o
.ToString () != "12")
490 // Test fields with big offsets
491 public static int test_0_fields_with_big_offsets () {
492 StructWithBigOffsets s
= new StructWithBigOffsets ();
493 StructWithBigOffsets s2
= new StructWithBigOffsets ();
519 if (s2
.i
!= 0xdeadbeef)
521 if (s2
.l
!= 0xcafebabe)
540 int buf_length
, buf_offset
;
548 public long Seek (long position
) {
550 /* interaction between the register allocator and
551 * allocating arguments to registers */
552 if (pos
>= buf_start
&& pos
<= buf_start
+ buf_length
) {
553 buf_offset
= (int) (pos
- buf_start
);
561 public static int test_0_seektest () {
562 TestRegA t
= new TestRegA ();
563 return (int)t
.Seek (0);
566 class Super
: ICloneable
{
567 public virtual object Clone () {
574 public static int test_0_null_cast () {
582 public static int test_0_super_cast () {
583 Duper d
= new Duper ();
597 d
= (Duper
)(object)sup
;
604 public static int test_0_super_cast_array () {
605 Duper
[] d
= new Duper
[0];
616 if (!(d
is Object
[]))
619 d
= (Duper
[])(object[])sup
;
626 public static int test_0_multi_array_cast () {
627 Duper
[,] d
= new Duper
[1, 1];
631 o
[0, 0] = new Super ();
634 catch (ArrayTypeMismatchException
) {
640 public static int test_0_vector_array_cast () {
641 Array arr1
= Array
.CreateInstance (typeof (int), new int[] {1}
, new int[] {0}
);
642 Array arr2
= Array
.CreateInstance (typeof (int), new int[] {1}
, new int[] {10}
);
643 Array arr5
= Array
.CreateInstance (typeof (string), new int[] {1}
, new int[] {10}
);
645 if (arr1
.GetType () != typeof (int[]))
648 if (arr2
.GetType () == typeof (int[]))
659 catch (InvalidCastException
) {
664 var as_object_arr
= arr5
as object [];
665 if (as_object_arr
!= null)
668 int [,] [] arr3
= new int [1, 1] [];
670 int [,] [] arr4
= (int [,] [])o
;
675 public static int test_0_enum_array_cast () {
676 TypeCode
[] tc
= new TypeCode
[0];
685 if (a
is ValueType
[])
699 vta
= (ValueType
[])a
;
716 public static int test_0_more_cast_corner_cases () {
717 ValueType
[] vta
= new ValueType
[0];
718 Enum
[] ea
= new Enum
[0];
723 if (!(a
is object[]))
725 if (!(a
is ValueType
[]))
730 if (!(a
is object[]))
732 if (!(a
is ValueType
[]))
792 object arr
= new int [10];
793 if (arr
is IList
<int?>)
799 public static int test_0_cast_iface_array () {
800 object o
= new ICloneable
[0];
801 object o2
= new Duper
[0];
805 if (!(o
is object[]))
807 if (!(o2
is ICloneable
[]))
821 t
= (ICloneable
[])o2
;
837 if (!(o
is ICloneable
[]))
840 /* add tests for interfaces that 'inherit' interfaces */
844 public static unsafe int test_0_pointer_array() {
845 int*[] ipa
= new int* [0];
853 if (a
is ValueType
[])
863 public static string[] StringValues
= { "Val1", "Val2", "Val3" }
;
865 public static IEnumerable
<string> GetStringValues ()
867 foreach (string val
in StringValues
)
871 public static int test_0_cast_special_iface () {
873 IEnumerable
<string> strings
= GetStringValues ();
874 IList
<string> stringIList
= (IList
<string>) strings
;
876 // No exception thrown. Maybe it's an actual IList ?
877 // Make sure it's not bluffing
878 if (!"Val2".Equals (stringIList
[1]))
880 } catch (InvalidCastException
) {
886 private static int[] daysmonthleap
= { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
;
888 private static int AbsoluteDays (int year
, int month
, int day
)
891 int[] days
= daysmonthleap
;
894 return ((day
-1) + temp
+ (365* (year
-1)) + ((year
-1)/4) - ((year
-1)/100) + ((year
-1)/400));
897 public static int test_719162_complex_div () {
898 int adays
= AbsoluteDays (1970, 1, 1);
902 delegate int GetIntDel ();
904 static int return4 () {
912 public static int test_2_static_delegate () {
913 GetIntDel del
= new GetIntDel (return4
);
920 public static int test_2_instance_delegate () {
921 Tests t
= new Tests ();
922 GetIntDel del
= new GetIntDel (t
.return5
);
929 class InstanceDelegateTest
{
932 public int return_field () {
937 public static int test_2_instance_delegate_with_field () {
938 InstanceDelegateTest t
= new InstanceDelegateTest () { a = 1337 }
;
939 GetIntDel del
= new GetIntDel (t
.return_field
);
946 interface IFaceVirtualDel
{
950 struct VtypeVirtualDelStruct
: IFaceVirtualDel
{
952 public int return_field_nonvirt () {
955 public int return_field () {
960 public static int test_42_vtype_delegate () {
961 var s
= new VtypeVirtualDelStruct () { f = 42 }
;
962 Func
<int> f
= s
.return_field_nonvirt
;
966 public static int test_42_vtype_virtual_delegate () {
967 IFaceVirtualDel s
= new VtypeVirtualDelStruct () { f = 42 }
;
968 Func
<int> f
= s
.return_field
;
972 public static int test_1_store_decimal () {
973 decimal[,] a
= {{1}}
;
980 public static int test_2_intptr_stobj () {
981 System
.IntPtr
[] arr
= { new System.IntPtr () }
;
983 if (arr
[0] != (System
.IntPtr
)0)
988 static int llmult (int a
, int b
, int c
, int d
) {
989 return a
+ b
+ c
+ d
;
993 * Test that evaluation of complex arguments does not overwrite the
994 * arguments already in outgoing registers.
996 public static int test_155_regalloc () {
1002 int[] arr
= new int [5];
1004 return llmult (arr
[c
+ d
], 150, 5, 0);
1007 static bool large_struct_test (Large a
, Large b
, Large c
, Large d
)
1009 if (!a
.check ()) return false;
1010 if (!b
.check ()) return false;
1011 if (!c
.check ()) return false;
1012 if (!d
.check ()) return false;
1016 public static int test_2_large_struct_pass ()
1027 if (large_struct_test (a
, b
, c
, d
))
1032 public static unsafe int test_0_pin_string () {
1034 fixed (char *c
= x
) {
1041 public static int my_flags
;
1042 public static int test_0_and_cmp_static ()
1045 /* various forms of test [mem], imm */
1047 my_flags
= 0x01020304;
1049 if ((my_flags
& 0x01020304) == 0)
1052 if ((my_flags
& 0x00000304) == 0)
1055 if ((my_flags
& 0x00000004) == 0)
1058 if ((my_flags
& 0x00000300) == 0)
1061 if ((my_flags
& 0x00020000) == 0)
1064 if ((my_flags
& 0x01000000) == 0)
1071 public static int test_0_byte_compares ()
1077 if (!(b
< System
.Byte
.MaxValue
))
1080 if (!(b
<= System
.Byte
.MaxValue
))
1086 static Nullable
<bool> s_nullb
;
1087 static AStruct s_struct1
;
1089 /* test if VES uses correct sizes for value type write to static field */
1090 public static int test_0_static_nullable_bool () {
1091 s_struct1
= new AStruct (0x1337dead);
1093 /* make sure that the write to s_nullb didn't smash the value after it */
1094 if (s_struct1
.i
!= 0x1337dead)
1099 public static int test_71_long_shift_right () {
1100 ulong value = 38654838087;
1102 byte [] buffer
= new byte [1];
1103 buffer
[x
] = ((byte)(value >> x
));
1108 public static int test_0_addsub_mem ()
1125 public static int test_0_sh32_mem ()
1127 y
= 0x0102130405060708;
1130 if (y
!= 0x01021304)
1133 y
= 0x0102130405060708;
1136 if (y
!= 0x0506070800000000)
1139 x
= 0x0102130405060708;
1142 if (x
!= 0x0506070800000000)
1149 static uint dum_de_dum
= 1;
1150 public static int test_0_long_arg_opt ()
1152 return Foo (0x1234567887654321, dum_de_dum
);
1155 static int Foo (ulong x
, ulong y
)
1157 if (x
!= 0x1234567887654321)
1166 public static int test_0_long_ret_opt ()
1169 if (x
!= 0x1234567887654321)
1180 return 0x1234567887654321;
1188 /* from bug# 71515 */
1189 static int counter
= 0;
1190 static bool WriteStuff () {
1194 public static int test_0_cond_branch_side_effects () {
1204 public static int arg_only_written (string file_name
, int[]
1206 if (file_name
== null)
1215 public static int[] foo () {
1219 public static void bar (int i
) {
1223 public static int test_0_arg_only_written ()
1225 return arg_only_written ("md.in", null);
1228 static long position
= 0;
1230 public static int test_4_static_inc_long () {
1238 return (int)position
;
1243 public FooStruct (long l
) {
1247 public static int test_0_calls_opcode_emulation () {
1248 // Test that emulated opcodes do not clobber arguments already in
1252 new FooStruct (val
* 10000);
1257 public static int test_0_intrins_string_length () {
1260 return (s
.Length
== 3) ? 0 : 1;
1263 public static int test_0_intrins_string_chars () {
1266 return (s
[0] == 'A' && s
[1] == 'B' && s
[2] == 'C') ? 0 : 1;
1269 public static int test_0_intrins_object_gettype () {
1272 return (o
.GetType () == typeof (int)) ? 0 : 1;
1275 public static int test_0_intrins_object_gethashcode () {
1276 object o
= new Object ();
1278 return (o
.GetHashCode () == o
.GetHashCode ()) ? 0 : 1;
1284 public static int test_0_intrins_object_ctor () {
1285 object o
= new FooClass ();
1287 return (o
!= null) ? 0 : 1;
1290 public static int test_0_intrins_array_rank () {
1291 int[,] a
= new int [10, 10];
1293 return (a
.Rank
== 2) ? 0 : 1;
1296 public static int test_0_intrins_array_length () {
1297 int[,] a
= new int [10, 10];
1300 return (a2
.Length
== 100) ? 0 : 1;
1303 public static int test_0_intrins_runtimehelpers_offset_to_string_data () {
1304 int i
= RuntimeHelpers
.OffsetToStringData
;
1309 public static int test_0_intrins_string_setchar () {
1310 StringBuilder sb
= new StringBuilder ("ABC");
1314 return sb
.ToString () == "ADC" ? 0 : 1;
1324 public static int test_0_intrins_enum_hasflag () {
1325 var e
= FlagsEnum
.A
| FlagsEnum
.B
;
1327 if (!e
.HasFlag (FlagsEnum
.A
))
1329 if (!e
.HasFlag (FlagsEnum
.A
| FlagsEnum
.B
))
1331 if (!e
.HasFlag (FlagsEnum
.None
))
1333 if (e
.HasFlag (FlagsEnum
.C
))
1339 bool allowLocation
= true;
1343 public static int test_0_regress_78990_unaligned_structs () {
1349 public static unsafe int test_97_negative_index () {
1350 char[] arr
= new char[] {'a', 'b'}
;
1351 fixed (char *p
= arr
) {
1359 public static int test_0_unsigned_right_shift_imm0 () {
1361 byte[] data
= new byte[256];
1362 for (int i
= 0; i
< 1; i
++)
1363 temp
= (uint)(data
[temp
>> 24] | data
[temp
>> 0]);
1368 public virtual int foo () {
1373 sealed class Bar2
: Foo2
{
1374 public override int foo () {
1379 public static int test_0_abcrem_check_this_removal () {
1380 Bar2 b
= new Bar2 ();
1382 // The check_this generated here by the JIT should be removed
1388 static int invoke_twice (Bar2 b
) {
1390 // The check_this generated here by the JIT should be removed
1396 public static int test_0_abcrem_check_this_removal2 () {
1397 Bar2 b
= new Bar2 ();
1405 public static int test_0_array_access_64_bit () {
1406 int[] arr2
= new int [10];
1407 for (int i
= 0; i
< 10; ++i
)
1409 string s
= "ABCDEFGH";
1411 byte[] arr
= new byte [4];
1417 int len
= arr
[0] | (arr
[1] << 8) | (arr
[2] << 16) | (arr
[3] << 24);
1418 int len2
= - (len
+ 2);
1420 // Test array and string access with a 32 bit value whose upper 32 bits are
1423 if (arr2
[len2
] != 2)
1425 if (s
[len2
] != 'C')
1430 public static float return_float () {
1435 [Category ("!BITCODE")] // bug #59953
1436 public static int test_0_float_return_spill () {
1437 // The return value of return_float () is spilled because of the
1439 object o
= return_float ();
1440 float f
= return_float ();
1441 return (float)o
== f
? 0 : 1;
1446 public static float pi
= 3.14f
;
1448 public float float_field
;
1451 public static int test_0_ldsfld_soft_float () {
1452 if (R4Holder
.pi
== 3.14f
)
1458 public static int test_0_ldfld_stfld_soft_float () {
1459 R4Holder h
= new R4Holder ();
1460 h
.float_field
= 3.14f
;
1462 if (h
.float_field
== 3.14f
)
1468 class R4HolderRemote
: MarshalByRefObject
{
1469 public static float pi
= 3.14f
;
1471 public float float_field
;
1474 public static int test_0_ldfld_stfld_soft_float_remote () {
1475 R4HolderRemote h
= new R4HolderRemote ();
1476 h
.float_field
= 3.14f
;
1478 if (h
.float_field
== 3.14f
)
1484 public static int test_0_locals_soft_float () {
1500 static float pass_vtype_return_float (AStruct2 s
) {
1501 return s
.i
+ s
.j
== 6 ? 1.0f
: -1.0f
;
1504 public static int test_0_vtype_arg_soft_float () {
1505 return pass_vtype_return_float (new AStruct2 () { i = 2, j = 4 }
) > 0.0 ? 0 : 1;
1508 static int range_check_strlen (int i
, string s
) {
1509 if (i
< 0 || i
> s
.Length
)
1515 public static int test_0_range_check_opt () {
1516 if (range_check_strlen (0, "A") != 0)
1518 if (range_check_strlen (1, "A") != 0)
1520 if (range_check_strlen (2, "A") != 1)
1522 if (range_check_strlen (-100, "A") != 1)
1527 static int test_0_array_get_set_soft_float () {
1528 float[,] arr
= new float [2, 2];
1530 return arr
[0, 0] == 256f
? 0 : 1;
1534 struct Bug506915 { public int val; }
1535 static int test_2_ldobj_stobj_optization ()
1538 var a
= new Bug506915 ();
1539 var b
= new Bug506915 ();
1540 if (i
.GetHashCode () == 99)
1542 var array
= new Bug506915
[2];
1544 array
[1] = (i
== 0) ? a
: array
[0];
1546 return array
[1].val
;
1549 /* mcs can't compile this (#646744) */
1551 static void InitMe (out Gamma noMercyWithTheStack
) {
1552 noMercyWithTheStack
= new Gamma ();
1555 static int FunNoInline () {
1557 if (x
> 344 && x
< 22)
1562 static float DoNothingButDontInline (float a
, int b
) {
1565 else if (b
< 0 && b
> 10)
1571 * The local register allocator emits loadr8_membase and storer8_membase
1572 * to do spilling. This code is generated after mono_arch_lowering_pass so
1573 * mono_arch_output_basic_block must know how to deal with big offsets.
1574 * This only happens because the call in middle forces the temp for "(float)obj"
1577 public static int test_0_float_load_and_store_with_big_offset ()
1580 Gamma noMercyWithTheStack
;
1583 InitMe (out noMercyWithTheStack
);
1585 res
= DoNothingButDontInline ((float)obj
, FunNoInline ());
1597 static int vtype_phi (VTypePhi v1
, VTypePhi v2
, bool first
) {
1598 VTypePhi v
= first
? v1
: v2
;
1603 static int test_0_vtype_phi ()
1605 VTypePhi v1
= new VTypePhi () { i = 1 }
;
1606 VTypePhi v2
= new VTypePhi () { i = 2 }
;
1608 if (vtype_phi (v1
, v2
, true) != 1)
1610 if (vtype_phi (v1
, v2
, false) != 2)
1616 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1617 static void UseValue (int index
)
1621 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1622 static bool IsFalse ()
1627 static int test_0_llvm_moving_faulting_loads ()
1629 int[] indexes
= null;
1632 indexes
= new int[0];
1635 while (IsFalse ()) {
1636 UseValue (indexes
[0]);
1637 UseValue (indexes
[0]);
1643 public static bool flag
;
1647 internal static B
[] d
;
1654 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1655 static int regress_679467_inner () {
1664 * FIXME: This fails with AOT #703317.
1667 static int test_0_multiple_cctor_calls_regress_679467 () {
1669 return regress_679467_inner ();
1673 static int test_0_char_ctor () {
1674 string s
= new String (new char[] { 'A', 'B' }
, 0, 1);
1678 static object mInstance
= null;
1680 [MethodImpl(MethodImplOptions
.Synchronized
)]
1681 public static object getInstance() {
1682 if (mInstance
== null)
1683 mInstance
= new object();
1687 static int test_0_synchronized () {
1697 public static BStruct
foo () {
1698 return new BStruct () { t = typeof (T) }
;
1702 delegate BStruct
ADelegate ();
1704 static int test_0_regress_10601 () {
1705 var act
= (ADelegate
)(Del
<string>.foo
);
1707 if (b
.t
!= typeof (string))
1712 static int test_0_regress_11058 () {
1713 int foo
= -252674008;
1714 int foo2
= (int)(foo ^
0xF0F0F0F0); // = 28888
1715 var arr
= new byte[foo2
].Length
;
1719 public static void do_throw () {
1720 throw new Exception ();
1723 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1724 static void empty () {
1728 public static int test_0_llvm_inline_throw () {
1731 } catch (Exception
) {
1738 enum ByteEnum
: byte {
1752 public static int test_0_14217 () {
1753 t_14217_inner (new BugStruct ());
1757 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1758 static void t_14217_inner (BugStruct bug
) {
1761 [StructLayout(LayoutKind
.Sequential
)]
1762 public struct EmptyStruct
{
1766 public static EmptyStruct s
;
1770 static int test_0_empty_struct_as_static () {
1771 var s
= EmptyClass
.s
;
1776 static int test_0_int_to_r4 () {
1777 return int_to_r4_inner (255);
1780 static int int_to_r4_inner (int value1
) {
1782 float mult
= sub
* 1f
;
1783 if (mult
!= -255.0f
)
1790 public double a
, b
, c
, d
;
1793 static double arm64_hfa_on_stack_inner (double d1
, double d2
, double d3
, double d4
, double d5
, double d6
, double d7
, double d8
, HFA4D s
) {
1794 return s
.a
+ s
.b
+ s
.c
+ s
.d
;
1797 static int test_0_arm64_hfa_on_stack () {
1798 var s
= new HFA4D () { a = 1.0, b = 2.0, c = 3.0, d = 4.0 }
;
1799 var res
= arm64_hfa_on_stack_inner (1, 2, 3, 4, 5, 6, 7, 8, s
);
1800 return res
== 10.0 ? 0 : 1;
1804 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1805 public unsafe void EncodeIntoBuffer(char* value, int valueLength
, char* buffer
, int bufferLength
) {
1809 static unsafe int test_0_mul_ovf_regress_36052 () {
1810 var p
= new MulOvfClass ();
1812 string typeName
= typeof(int).Name
;
1813 int bufferSize
= 45;
1815 fixed (char* value = typeName
) {
1816 char* buffer
= stackalloc char[bufferSize
];
1817 p
.EncodeIntoBuffer(value, typeName
.Length
, buffer
, bufferSize
);
1823 public int a
, b
, c
, d
;
1826 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1827 static int pass_struct16 (object o0
, object o2
, object o3
, object o4
, object o5
, object o6
, object o7
, Struct16 o8
) {
1828 // This disables LLVM
1835 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1836 static int pass_struct16 (object o0
, object o2
, object o3
, object o6
, object o7
, Struct16 o8
) {
1837 return pass_struct16 (o0
, o2
, null, o3
, null, o6
, o7
, o8
);
1840 public static int test_42_pass_16byte_struct_split () {
1841 return pass_struct16 (null, null, null, null, null, new Struct16 () { a = 42 }
);
1844 public interface IComparer2
1849 public class AClass
: IComparer2
{
1850 public Type foo
<T
> () {
1855 public static int test_0_delegate_to_virtual_generic_on_ifaces () {
1856 IComparer2 c
= new AClass ();
1858 Func
<Type
> f
= c
.foo
<string>;
1859 return f () == typeof(string) ? 0 : 1;
1862 public enum ByteEnum2
: byte {
1866 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1867 public static int enum_arg_zero_extend (ByteEnum2 b
) {
1871 public static int test_142_byte_enum_arg_zero_extend () {
1872 return enum_arg_zero_extend (ByteEnum2
.High
);
1875 enum Mine { One, Two }
1877 public static int test_0_enum_gethashcode_opt () {
1879 for (int i
= 0; i
< 1000000; ++i
)
1880 sum
+= Mine
.Two
.GetHashCode();
1885 public static int test_0_typedref () {
1887 System
.TypedReference r
= __makeref(i
);
1888 System
.Type t
= __reftype(r
);
1890 if (t
!= typeof (int))
1892 int j
= __refvalue(r
, int);
1897 object o
= __refvalue (r
, object);
1898 } catch (InvalidCastException
) {
1904 enum FooEnum { Bar }
1905 //https://github.com/mono/mono/issues/6666
1906 public static int test_0_bad_unbox_nullable_of_enum () {
1908 var enumValue
= FooEnum
.Bar
;
1909 object value = (int)enumValue
;
1910 var res
= (FooEnum
?)value; // Should throw
1911 } catch (InvalidCastException
) {
1917 //https://github.com/mono/mono/issues/6666
1918 public static int test_0_unbox_nullable_of_enum () {
1920 var enumValue
= FooEnum
.Bar
;
1921 object value = (object)enumValue
;
1922 var res
= (FooEnum
?)value; // Should not throw
1923 } catch (InvalidCastException
) {
1929 static void decode (out sbyte v
) {
1935 public static int test_0_alias_analysis_sign_extend () {
1939 return t
== -122 ? 0 : 1;
1942 public interface IFoo
1947 public class IFooImpl
: IFoo
1949 public int MyInt
=> 0;
1953 public static int test_0_store_to_magic_iface_array ()
1955 ICollection
<IFoo
> arr1
= new IFooImpl
[1] { new IFooImpl() }
;
1956 ICollection
<IFoo
> arr2
= new IFooImpl
[1] { new IFooImpl() }
;
1958 ICollection
<IFoo
>[] a2d
= new ICollection
<IFoo
>[2] {
1966 static volatile bool abool
;
1968 public static unsafe int test_0_stind_r4_float32_stack_merge () {
1969 Single
* dataPtr
= stackalloc Single
[4];
1971 dataPtr
[0] = abool
? 1.0f
: 2.0f
;
1972 return dataPtr
[0] == 1.0f
? 0 : 1;
1978 class BClass1
: AClass1
{
1984 public static int test_0_array_of_magic_iface () {
1985 // Need to make this an object otherwise csc removes the cast
1986 object d
= new [] { new [] { new BClass1 () }
};
1987 if (!(d
is IList
<AClass1
> []))
1989 if (d
is IList
<CClass1
> [])
1991 var e2
= (IList
<AClass1
> []) d
;
1995 class SimpleContainer
{
1996 public Simple simple1
;
1997 public Simple simple2
;
1999 public static Simple constsimple
;
2001 public int SetFields () {
2002 constsimple
.a
= 0x1337;
2003 simple1
= simple2
= constsimple
;
2004 return simple1
.a
- simple2
.a
;
2008 public static int test_0_dup_vtype () {
2009 return new SimpleContainer ().SetFields ();
2012 public struct Vec3
{
2015 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
2016 public Vec3(int x
, int y
, int z
) {
2023 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
2024 public static int gh_11378_inner_1 (Vec3 p1
, Vec3 p2
) {
2032 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
2033 public static int gh_11378_inner_2 (Vec3 c
, Vec3 pos
) {
2034 return gh_11378_inner_1 (pos
, c
);
2037 static int gh_11378_inner_3 (Vec3 c
) {
2039 return gh_11378_inner_2 (c
, c2
);
2042 public static int test_2_gh_11378 () {
2043 return gh_11378_inner_3 (new Vec3(0, 2, -20));
2046 static int variable_with_constant_address
;
2048 public static int test_0_cfold_with_non_constant_ternary_op () {
2049 variable_with_constant_address
= 0;
2050 var old
= System
.Threading
.Interlocked
.CompareExchange(ref variable_with_constant_address
, 1, 0);
2051 return old
== 0 && variable_with_constant_address
== 1 ? 0 : 1;