Pinvoke symbols according to the new moonlight naming convention.
[mono-project.git] / mono / mini / objects.cs
blob3d849c64d053102816256281fcd9861c664dcda0
1 using System;
2 using System.Text;
3 using System.Reflection;
4 using System.Runtime.InteropServices;
5 using System.Runtime.CompilerServices;
7 /*
8 * Regression tests for the mono JIT.
10 * Each test needs to be of the form:
12 * static int test_<result>_<name> ();
14 * where <result> is an integer (the value that needs to be returned by
15 * the method to make it pass.
16 * <name> is a user-displayed name used to identify the test.
18 * The tests can be driven in two ways:
19 * *) running the program directly: Main() uses reflection to find and invoke
20 * the test methods (this is useful mostly to check that the tests are correct)
21 * *) with the --regression switch of the jit (this is the preferred way since
22 * all the tests will be run with optimizations on and off)
24 * The reflection logic could be moved to a .dll since we need at least another
25 * regression test file written in IL code to have better control on how
26 * the IL code looks.
29 struct Simple {
30 public int a;
31 public byte b;
32 public short c;
33 public long d;
36 struct Small {
37 public byte b1;
38 public byte b2;
41 // Size=2, Align=1
42 struct Foo {
43 bool b1;
44 bool b2;
47 struct Large {
48 int one;
49 int two;
50 long three;
51 long four;
52 int five;
53 long six;
54 int seven;
55 long eight;
56 long nine;
57 long ten;
59 public void populate ()
61 one = 1; two = 2;
62 three = 3; four = 4;
63 five = 5; six = 6;
64 seven = 7; eight = 8;
65 nine = 9; ten = 10;
67 public bool check ()
69 return one == 1 && two == 2 &&
70 three == 3 && four == 4 &&
71 five == 5 && six == 6 &&
72 seven == 7 && eight == 8 &&
73 nine == 9 && ten == 10;
77 class Sample {
78 public int a;
79 public Sample (int v) {
80 a = v;
84 [StructLayout ( LayoutKind.Explicit )]
85 struct StructWithBigOffsets {
86 [ FieldOffset(10000) ] public byte b;
87 [ FieldOffset(10001) ] public sbyte sb;
88 [ FieldOffset(11000) ] public short s;
89 [ FieldOffset(11002) ] public ushort us;
90 [ FieldOffset(12000) ] public uint i;
91 [ FieldOffset(12004) ] public int si;
92 [ FieldOffset(13000) ] public long l;
93 [ FieldOffset(14000) ] public float f;
94 [ FieldOffset(15000) ] public double d;
97 enum SampleEnum {
103 struct Alpha {
104 public long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v;
107 struct Beta {
108 public Alpha a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v;
111 struct Gamma {
112 public Beta a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v;
115 class Tests {
117 static int Main () {
118 return TestDriver.RunTests (typeof (Tests));
121 public static int test_0_return () {
122 Simple s;
123 s.a = 1;
124 s.b = 2;
125 s.c = (short)(s.a + s.b);
126 s.d = 4;
127 return s.a - 1;
130 public static int test_0_string_access () {
131 string s = "Hello";
132 if (s [1] != 'e')
133 return 1;
134 return 0;
137 public static int test_0_string_virtual_call () {
138 string s = "Hello";
139 string s2 = s.ToString ();
140 if (s2 [1] != 'e')
141 return 1;
142 return 0;
145 public static int test_0_iface_call () {
146 string s = "Hello";
147 object o = ((ICloneable)s).Clone ();
148 return 0;
151 public static int test_5_newobj () {
152 Sample s = new Sample (5);
153 return s.a;
156 public static int test_4_box () {
157 object obj = 4;
158 return (int)obj;
161 public static int test_0_enum_unbox () {
162 SampleEnum x = SampleEnum.A;
163 object o = x;
165 int res = 1;
167 res = (int)o;
169 return res;
172 static Simple get_simple (int v) {
173 Simple r = new Simple ();
174 r.a = v;
175 r.b = (byte)(v + 1);
176 r.c = (short)(v + 2);
177 r.d = v + 3;
179 return r;
182 public static int test_3_return_struct () {
183 Simple v = get_simple (1);
185 if (v.a != 1)
186 return 0;
187 if (v.b != 2)
188 return 0;
189 if (v.c != 3)
190 return 0;
191 if (v.d != 4)
192 return 0;
193 return 3;
196 public virtual Simple v_get_simple (int v)
198 return get_simple (v);
201 public static int test_2_return_struct_virtual () {
202 Tests t = new Tests ();
203 Simple v = t.v_get_simple (2);
205 if (v.a != 2)
206 return 0;
207 if (v.b != 3)
208 return 0;
209 if (v.c != 4)
210 return 0;
211 if (v.d != 5)
212 return 0;
213 return 2;
216 static int receive_simple (int a, Simple v, int b) {
217 if (v.a != 1)
218 return 1;
219 if (v.b != 2)
220 return 2;
221 if (v.c != 3)
222 return 3;
223 if (v.d != 4)
224 return 4;
225 if (a != 7)
226 return 5;
227 if (b != 9)
228 return 6;
229 return 0;
232 public static int test_5_pass_struct () {
233 Simple v = get_simple (1);
234 if (receive_simple (7, v, 9) != 0)
235 return 0;
236 if (receive_simple (7, get_simple (1), 9) != 0)
237 return 1;
238 return 5;
241 static Simple s_v;
242 public static int test_5_pass_static_struct () {
243 s_v = get_simple (1);
244 if (receive_simple (7, s_v, 9) != 0)
245 return 0;
246 return 5;
249 // Test alignment of small structs
251 static Small get_small (byte v) {
252 Small r = new Small ();
254 r.b1 = v;
255 r.b2 = (byte)(v + 1);
257 return r;
260 static Small return_small (Small s) {
261 return s;
264 static int receive_small (int a, Small v, int b) {
265 if (v.b1 != 1)
266 return 1;
267 if (v.b2 != 2)
268 return 2;
269 return 0;
272 static int receive_small_sparc_many_args (int a, int a2, int a3, int a4, int a5, int a6, Small v, int b) {
273 if (v.b1 != 1)
274 return 1;
275 if (v.b2 != 2)
276 return 2;
277 return 0;
280 public static int test_5_pass_small_struct () {
281 Small v = get_small (1);
282 if (receive_small (7, v, 9) != 0)
283 return 0;
284 if (receive_small (7, get_small (1), 9) != 0)
285 return 1;
286 if (receive_small_sparc_many_args (1, 2, 3, 4, 5, 6, v, 9) != 0)
287 return 2;
288 v = return_small (v);
289 if (v.b1 != 1)
290 return 3;
291 if (v.b2 != 2)
292 return 4;
293 return 5;
296 // 64-bits, 32-bit aligned
297 struct struct1 {
298 public int a;
299 public int b;
302 static int check_struct1(struct1 x) {
303 if (x.a != 1)
304 return 1;
305 if (x.b != 2)
306 return 2;
307 return 0;
310 static int pass_struct1(int a, int b, struct1 x) {
311 if (a != 3)
312 return 3;
313 if (b != 4)
314 return 4;
315 return check_struct1(x);
318 static int pass_struct1(int a, struct1 x) {
319 if (a != 3)
320 return 3;
321 return check_struct1(x);
324 static int pass_struct1(struct1 x) {
325 return check_struct1(x);
328 public static int test_0_struct1_args () {
329 int r;
330 struct1 x;
332 x.a = 1;
333 x.b = 2;
334 if ((r = check_struct1(x)) != 0)
335 return r;
336 if ((r = pass_struct1(x)) != 0)
337 return r + 10;
338 if ((r = pass_struct1(3, x)) != 0)
339 return r + 20;
340 if ((r = pass_struct1(3, 4, x)) != 0)
341 return r + 30;
342 return 0;
345 // 64-bits, 64-bit aligned
346 struct struct2 {
347 public long a;
350 static int check_struct2(struct2 x) {
351 if (x.a != 1)
352 return 1;
353 return 0;
356 static int pass_struct2(int a, int b, int c, struct2 x) {
357 if (a != 3)
358 return 3;
359 if (b != 4)
360 return 4;
361 if (c != 5)
362 return 5;
363 return check_struct2(x);
366 static int pass_struct2(int a, int b, struct2 x) {
367 if (a != 3)
368 return 3;
369 if (b != 4)
370 return 4;
371 return check_struct2(x);
374 static int pass_struct2(int a, struct2 x) {
375 if (a != 3)
376 return 3;
377 return check_struct2(x);
380 static int pass_struct2(struct2 x) {
381 return check_struct2(x);
384 public static int test_0_struct2_args () {
385 int r;
386 struct2 x;
388 x.a = 1;
389 if ((r = check_struct2(x)) != 0)
390 return r;
391 if ((r = pass_struct2(x)) != 0)
392 return r + 10;
393 if ((r = pass_struct2(3, x)) != 0)
394 return r + 20;
395 if ((r = pass_struct2(3, 4, x)) != 0)
396 return r + 30;
397 if ((r = pass_struct2(3, 4, 5, x)) != 0)
398 return r + 40;
399 return 0;
402 // 128 bits
403 struct Struct3 {
404 public long i, j, k, l;
407 static int pass_struct3 (int i, int j, int k, int l, int m, int n, int o, int p, Struct3 s, int q) {
408 if (s.i + s.j + s.k + s.l != 10)
409 return 1;
410 else
411 return 0;
414 public static int test_0_struct3_args () {
415 Struct3 s = new Struct3 ();
416 s.i = 1;
417 s.j = 2;
418 s.k = 3;
419 s.l = 4;
421 return pass_struct3 (1, 2, 3, 4, 5, 6, 7, 8, s, 9);
424 // Struct with unaligned size on 64 bit machines
425 struct Struct4 {
426 public int i, j, k, l, m;
427 public int i1, i2, i3, i4, i5, i6;
430 static int pass_struct4 (Struct4 s) {
431 if (s.i + s.j + s.k + s.l + s.m != 15)
432 return 1;
433 else
434 return 0;
437 public static int test_0_struct4_args () {
438 Struct4 s = new Struct4 ();
439 s.i = 1;
440 s.j = 2;
441 s.k = 3;
442 s.l = 4;
443 s.m = 5;
445 return pass_struct4 (s);
450 struct AStruct {
451 public int i;
453 public AStruct (int i) {
454 this.i = i;
457 public override int GetHashCode () {
458 return i;
462 // Test that vtypes are unboxed during a virtual call
463 public static int test_44_unbox_trampoline () {
464 AStruct s = new AStruct (44);
465 object o = s;
466 return o.GetHashCode ();
469 public static int test_0_unbox_trampoline2 () {
470 int i = 12;
471 object o = i;
473 if (i.ToString () != "12")
474 return 1;
475 if (((Int32)o).ToString () != "12")
476 return 2;
477 if (o.ToString () != "12")
478 return 3;
479 return 0;
482 // Test fields with big offsets
483 public static int test_0_fields_with_big_offsets () {
484 StructWithBigOffsets s = new StructWithBigOffsets ();
485 StructWithBigOffsets s2 = new StructWithBigOffsets ();
487 s.b = 0xde;
488 s.sb = 0xe;
489 s.s = 0x12de;
490 s.us = 0x12da;
491 s.i = 0xdeadbeef;
492 s.si = 0xcafe;
493 s.l = 0xcafebabe;
494 s.f = 3.14F;
495 s.d = 3.14;
497 s2.b = s.b;
498 s2.sb = s.sb;
499 s2.s = s.s;
500 s2.us = s.us;
501 s2.i = s.i;
502 s2.si = s.si;
503 s2.l = s.l;
504 s2.f = s.f;
505 s2.d = s.d;
507 if (s2.b != 0xde)
508 return 1;
509 if (s2.s != 0x12de)
510 return 2;
511 if (s2.i != 0xdeadbeef)
512 return 3;
513 if (s2.l != 0xcafebabe)
514 return 4;
515 if (s2.f != 3.14F)
516 return 5;
517 if (s2.d != 3.14)
518 return 6;
519 if (s2.sb != 0xe)
520 return 7;
521 if (s2.us != 0x12da)
522 return 9;
523 if (s2.si != 0xcafe)
524 return 10;
526 return 0;
529 class TestRegA {
531 long buf_start;
532 int buf_length, buf_offset;
534 public TestRegA () {
535 buf_start = 0;
536 buf_length = 0;
537 buf_offset = 0;
540 public long Seek (long position) {
541 long pos = position;
542 /* interaction between the register allocator and
543 * allocating arguments to registers */
544 if (pos >= buf_start && pos <= buf_start + buf_length) {
545 buf_offset = (int) (pos - buf_start);
546 return pos;
548 return buf_start;
553 public static int test_0_seektest () {
554 TestRegA t = new TestRegA ();
555 return (int)t.Seek (0);
558 class Super : ICloneable {
559 public virtual object Clone () {
560 return null;
563 class Duper: Super {
566 public static int test_0_null_cast () {
567 object o = null;
569 Super s = (Super)o;
571 return 0;
574 public static int test_0_super_cast () {
575 Duper d = new Duper ();
576 Super sup = d;
577 Object o = d;
579 if (!(o is Super))
580 return 1;
581 try {
582 d = (Duper)sup;
583 } catch {
584 return 2;
586 if (!(d is Object))
587 return 3;
588 try {
589 d = (Duper)(object)sup;
590 } catch {
591 return 4;
593 return 0;
596 public static int test_0_super_cast_array () {
597 Duper[] d = new Duper [0];
598 Super[] sup = d;
599 Object[] o = d;
601 if (!(o is Super[]))
602 return 1;
603 try {
604 d = (Duper[])sup;
605 } catch {
606 return 2;
608 if (!(d is Object[]))
609 return 3;
610 try {
611 d = (Duper[])(object[])sup;
612 } catch {
613 return 4;
615 return 0;
618 public static int test_0_multi_array_cast () {
619 Duper[,] d = new Duper [1, 1];
620 object[,] o = d;
622 try {
623 o [0, 0] = new Super ();
624 return 1;
626 catch (ArrayTypeMismatchException) {
629 return 0;
632 public static int test_0_vector_array_cast () {
633 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
634 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
636 if (arr1.GetType () != typeof (int[]))
637 return 1;
639 if (arr2.GetType () == typeof (int[]))
640 return 2;
642 int[] b;
644 b = (int[])arr1;
646 try {
647 b = (int[])arr2;
648 return 3;
650 catch (InvalidCastException) {
653 if (arr2 is int[])
654 return 4;
656 int [,] [] arr3 = new int [1, 1] [];
657 object o = arr3;
658 int [,] [] arr4 = (int [,] [])o;
660 return 0;
663 public static int test_0_enum_array_cast () {
664 TypeCode[] tc = new TypeCode [0];
665 object[] oa;
666 ValueType[] vta;
667 int[] inta;
668 Array a = tc;
669 bool ok;
671 if (a is object[])
672 return 1;
673 if (a is ValueType[])
674 return 2;
675 if (a is Enum[])
676 return 3;
677 try {
678 ok = false;
679 oa = (object[])a;
680 } catch {
681 ok = true;
683 if (!ok)
684 return 4;
685 try {
686 ok = false;
687 vta = (ValueType[])a;
688 } catch {
689 ok = true;
691 if (!ok)
692 return 5;
693 try {
694 ok = true;
695 inta = (int[])a;
696 } catch {
697 ok = false;
699 if (!ok)
700 return 6;
701 return 0;
704 public static int test_0_more_cast_corner_cases () {
705 ValueType[] vta = new ValueType [0];
706 Enum[] ea = new Enum [0];
707 Array a = vta;
708 object[] oa;
709 bool ok;
711 if (!(a is object[]))
712 return 1;
713 if (!(a is ValueType[]))
714 return 2;
715 if (a is Enum[])
716 return 3;
717 a = ea;
718 if (!(a is object[]))
719 return 4;
720 if (!(a is ValueType[]))
721 return 5;
722 if (!(a is Enum[]))
723 return 6;
725 try {
726 ok = true;
727 oa = (object[])a;
728 } catch {
729 ok = false;
731 if (!ok)
732 return 7;
734 try {
735 ok = true;
736 oa = (Enum[])a;
737 } catch {
738 ok = false;
740 if (!ok)
741 return 8;
743 try {
744 ok = true;
745 oa = (ValueType[])a;
746 } catch {
747 ok = false;
749 if (!ok)
750 return 9;
752 a = vta;
753 try {
754 ok = true;
755 oa = (object[])a;
756 } catch {
757 ok = false;
759 if (!ok)
760 return 10;
762 try {
763 ok = true;
764 oa = (ValueType[])a;
765 } catch {
766 ok = false;
768 if (!ok)
769 return 11;
771 try {
772 ok = false;
773 vta = (Enum[])a;
774 } catch {
775 ok = true;
777 if (!ok)
778 return 12;
779 return 0;
782 public static int test_0_cast_iface_array () {
783 object o = new ICloneable [0];
784 object o2 = new Duper [0];
785 object t;
786 bool ok;
788 if (!(o is object[]))
789 return 1;
790 if (!(o2 is ICloneable[]))
791 return 2;
793 try {
794 ok = true;
795 t = (object[])o;
796 } catch {
797 ok = false;
799 if (!ok)
800 return 3;
802 try {
803 ok = true;
804 t = (ICloneable[])o2;
805 } catch {
806 ok = false;
808 if (!ok)
809 return 4;
811 try {
812 ok = true;
813 t = (ICloneable[])o;
814 } catch {
815 ok = false;
817 if (!ok)
818 return 5;
820 if (!(o is ICloneable[]))
821 return 6;
823 /* add tests for interfaces that 'inherit' interfaces */
824 return 0;
827 private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
829 private static int AbsoluteDays (int year, int month, int day)
831 int temp = 0, m = 1;
832 int[] days = daysmonthleap;
833 while (m < month)
834 temp += days[m++];
835 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
838 public static int test_719162_complex_div () {
839 int adays = AbsoluteDays (1970, 1, 1);
840 return adays;
843 delegate int GetIntDel ();
845 static int return4 () {
846 return 4;
849 int return5 () {
850 return 5;
853 public static int test_2_static_delegate () {
854 GetIntDel del = new GetIntDel (return4);
855 int v = del ();
856 if (v != 4)
857 return 0;
858 return 2;
861 public static int test_2_instance_delegate () {
862 Tests t = new Tests ();
863 GetIntDel del = new GetIntDel (t.return5);
864 int v = del ();
865 if (v != 5)
866 return 0;
867 return 2;
870 public static int test_1_store_decimal () {
871 decimal[,] a = {{1}};
873 if (a[0,0] != 1m)
874 return 0;
875 return 1;
878 public static int test_2_intptr_stobj () {
879 System.IntPtr [] arr = { new System.IntPtr () };
881 if (arr [0] != (System.IntPtr)0)
882 return 1;
883 return 2;
886 static int llmult (int a, int b, int c, int d) {
887 return a + b + c + d;
891 * Test that evaluation of complex arguments does not overwrite the
892 * arguments already in outgoing registers.
894 public static int test_155_regalloc () {
895 int a = 10;
896 int b = 10;
898 int c = 0;
899 int d = 0;
900 int[] arr = new int [5];
902 return llmult (arr [c + d], 150, 5, 0);
905 static bool large_struct_test (Large a, Large b, Large c, Large d)
907 if (!a.check ()) return false;
908 if (!b.check ()) return false;
909 if (!c.check ()) return false;
910 if (!d.check ()) return false;
911 return true;
914 public static int test_2_large_struct_pass ()
916 Large a, b, c, d;
917 a = new Large ();
918 b = new Large ();
919 c = new Large ();
920 d = new Large ();
921 a.populate ();
922 b.populate ();
923 c.populate ();
924 d.populate ();
925 if (large_struct_test (a, b, c, d))
926 return 2;
927 return 0;
930 public static unsafe int test_0_pin_string () {
931 string x = "xxx";
932 fixed (char *c = x) {
933 if (*c != 'x')
934 return 1;
936 return 0;
939 public static int my_flags;
940 public static int test_0_and_cmp_static ()
943 /* various forms of test [mem], imm */
945 my_flags = 0x01020304;
947 if ((my_flags & 0x01020304) == 0)
948 return 1;
950 if ((my_flags & 0x00000304) == 0)
951 return 2;
953 if ((my_flags & 0x00000004) == 0)
954 return 3;
956 if ((my_flags & 0x00000300) == 0)
957 return 4;
959 if ((my_flags & 0x00020000) == 0)
960 return 5;
962 if ((my_flags & 0x01000000) == 0)
963 return 6;
965 return 0;
968 static byte b;
969 public static int test_0_byte_compares ()
971 b = 0xff;
972 if (b == -1)
973 return 1;
974 b = 0;
975 if (!(b < System.Byte.MaxValue))
976 return 2;
978 if (!(b <= System.Byte.MaxValue))
979 return 3;
981 return 0;
984 public static int test_71_long_shift_right () {
985 ulong value = 38654838087;
986 int x = 0;
987 byte [] buffer = new byte [1];
988 buffer [x] = ((byte)(value >> x));
989 return buffer [x];
992 static long x;
993 public static int test_0_addsub_mem ()
995 x = 0;
996 x += 5;
998 if (x != 5)
999 return 1;
1001 x -= 10;
1003 if (x != -5)
1004 return 2;
1006 return 0;
1009 static ulong y;
1010 public static int test_0_sh32_mem ()
1012 y = 0x0102130405060708;
1013 y >>= 32;
1015 if (y != 0x01021304)
1016 return 1;
1018 y = 0x0102130405060708;
1019 y <<= 32;
1021 if (y != 0x0506070800000000)
1022 return 2;
1024 x = 0x0102130405060708;
1025 x <<= 32;
1027 if (x != 0x0506070800000000)
1028 return 2;
1030 return 0;
1034 static uint dum_de_dum = 1;
1035 public static int test_0_long_arg_opt ()
1037 return Foo (0x1234567887654321, dum_de_dum);
1040 static int Foo (ulong x, ulong y)
1042 if (x != 0x1234567887654321)
1043 return 1;
1045 if (y != 1)
1046 return 2;
1048 return 0;
1051 public static int test_0_long_ret_opt ()
1053 ulong x = X ();
1054 if (x != 0x1234567887654321)
1055 return 1;
1056 ulong y = Y ();
1057 if (y != 1)
1058 return 2;
1060 return 0;
1063 static ulong X ()
1065 return 0x1234567887654321;
1068 static ulong Y ()
1070 return dum_de_dum;
1073 /* from bug# 71515 */
1074 static int counter = 0;
1075 static bool WriteStuff () {
1076 counter = 10;
1077 return true;
1079 public static int test_0_cond_branch_side_effects () {
1080 counter = 5;
1081 if (WriteStuff());
1082 if (counter == 10)
1083 return 0;
1084 return 1;
1087 // bug #74992
1088 public static int arg_only_written (string file_name, int[]
1089 ncells ) {
1090 if (file_name == null)
1091 return 1;
1093 ncells = foo ();
1094 bar (ncells [0]);
1096 return 0;
1099 public static int[] foo () {
1100 return new int [3];
1103 public static void bar (int i) {
1107 public static int test_0_arg_only_written ()
1109 return arg_only_written ("md.in", null);
1112 static long position = 0;
1114 public static int test_4_static_inc_long () {
1116 int count = 4;
1118 position = 0;
1120 position += count;
1122 return (int)position;
1125 struct FooStruct {
1127 public FooStruct (long l) {
1131 public static int test_0_calls_opcode_emulation () {
1132 // Test that emulated opcodes do not clobber arguments already in
1133 // out registers
1134 checked {
1135 long val = 10000;
1136 new FooStruct (val * 10000);
1138 return 0;
1141 public static int test_0_intrins_string_length () {
1142 string s = "ABC";
1144 return (s.Length == 3) ? 0 : 1;
1147 public static int test_0_intrins_string_chars () {
1148 string s = "ABC";
1150 return (s [0] == 'A' && s [1] == 'B' && s [2] == 'C') ? 0 : 1;
1153 public static int test_0_intrins_object_gettype () {
1154 object o = 1;
1156 return (o.GetType () == typeof (int)) ? 0 : 1;
1159 public static int test_0_intrins_object_gethashcode () {
1160 object o = new Object ();
1162 return (o.GetHashCode () == o.GetHashCode ()) ? 0 : 1;
1165 class FooClass {
1168 public static int test_0_intrins_object_ctor () {
1169 object o = new FooClass ();
1171 return (o != null) ? 0 : 1;
1174 public static int test_0_intrins_array_rank () {
1175 int[,] a = new int [10, 10];
1177 return (a.Rank == 2) ? 0 : 1;
1180 public static int test_0_intrins_array_length () {
1181 int[,] a = new int [10, 10];
1182 Array a2 = a;
1184 return (a2.Length == 100) ? 0 : 1;
1187 public static int test_0_intrins_runtimehelpers_offset_to_string_data () {
1188 int i = RuntimeHelpers.OffsetToStringData;
1190 return i - i;
1193 public static int test_0_intrins_string_setchar () {
1194 StringBuilder sb = new StringBuilder ("ABC");
1196 sb [1] = 'D';
1198 return sb.ToString () == "ADC" ? 0 : 1;
1201 public class Bar {
1202 bool allowLocation = true;
1203 Foo f = new Foo ();
1206 public static int test_0_regress_78990_unaligned_structs () {
1207 new Bar ();
1209 return 0;
1212 public static unsafe int test_97_negative_index () {
1213 char[] arr = new char[] {'a', 'b'};
1214 fixed (char *p = arr) {
1215 char *i = p + 2;
1216 char a = i[-2];
1217 return a;
1221 /* bug #82281 */
1222 public static int test_0_unsigned_right_shift_imm0 () {
1223 uint temp = 0;
1224 byte[] data = new byte[256];
1225 for (int i = 0; i < 1; i ++)
1226 temp = (uint)(data[temp >> 24] | data[temp >> 0]);
1227 return 0;
1230 class Foo2 {
1231 public virtual int foo () {
1232 return 0;
1236 sealed class Bar2 : Foo2 {
1237 public override int foo () {
1238 return 0;
1242 public static int test_0_abcrem_check_this_removal () {
1243 Bar2 b = new Bar2 ();
1245 // The check_this generated here by the JIT should be removed
1246 b.foo ();
1248 return 0;
1251 static int invoke_twice (Bar2 b) {
1252 b.foo ();
1253 // The check_this generated here by the JIT should be removed
1254 b.foo ();
1256 return 0;
1259 public static int test_0_abcrem_check_this_removal2 () {
1260 Bar2 b = new Bar2 ();
1262 invoke_twice (b);
1264 return 0;
1267 /* #346563 */
1268 public static int test_0_array_access_64_bit () {
1269 int[] arr2 = new int [10];
1270 for (int i = 0; i < 10; ++i)
1271 arr2 [i] = i;
1272 string s = "ABCDEFGH";
1274 byte[] arr = new byte [4];
1275 arr [0] = 252;
1276 arr [1] = 255;
1277 arr [2] = 255;
1278 arr [3] = 255;
1280 int len = arr [0] | (arr [1] << 8) | (arr [2] << 16) | (arr [3] << 24);
1281 int len2 = - (len + 2);
1283 // Test array and string access with a 32 bit value whose upper 32 bits are
1284 // undefined
1285 // len2 = 3
1286 if (arr2 [len2] != 2)
1287 return 1;
1288 if (s [len2] != 'C')
1289 return 2;
1290 return 0;
1293 public static float return_float () {
1294 return 1.4e-45f;
1297 public static int test_0_float_return_spill () {
1298 // The return value of return_float () is spilled because of the
1299 // boxing call
1300 object o = return_float ();
1301 float f = return_float ();
1302 return (float)o == f ? 0 : 1;
1305 class R4Holder {
1306 public static float pi = 3.14f;
1308 public float float_field;
1311 public static int test_0_ldsfld_soft_float () {
1312 if (R4Holder.pi == 3.14f)
1313 return 0;
1314 else
1315 return 1;
1318 public static int test_0_ldfld_stfld_soft_float () {
1319 R4Holder h = new R4Holder ();
1320 h.float_field = 3.14f;
1322 if (h.float_field == 3.14f)
1323 return 0;
1324 else
1325 return 1;
1328 class R4HolderRemote : MarshalByRefObject {
1329 public static float pi = 3.14f;
1331 public float float_field;
1334 public static int test_0_ldfld_stfld_soft_float_remote () {
1335 R4HolderRemote h = new R4HolderRemote ();
1336 h.float_field = 3.14f;
1338 if (h.float_field == 3.14f)
1339 return 0;
1340 else
1341 return 1;
1344 public static int test_0_locals_soft_float () {
1345 float f = 0.0f;
1347 f = 3.14f;
1349 if (f == 3.14f)
1350 return 0;
1351 else
1352 return 1;
1355 struct AStruct2 {
1356 public int i;
1357 public int j;
1360 static float pass_vtype_return_float (AStruct2 s) {
1361 return s.i + s.j == 6 ? 1.0f : -1.0f;
1364 public static int test_0_vtype_arg_soft_float () {
1365 return pass_vtype_return_float (new AStruct2 () { i = 2, j = 4 }) > 0.0 ? 0 : 1;
1368 static int range_check_strlen (int i, string s) {
1369 if (i < 0 || i > s.Length)
1370 return 1;
1371 else
1372 return 0;
1375 public static int test_0_range_check_opt () {
1376 if (range_check_strlen (0, "A") != 0)
1377 return 1;
1378 if (range_check_strlen (1, "A") != 0)
1379 return 2;
1380 if (range_check_strlen (2, "A") != 1)
1381 return 3;
1382 if (range_check_strlen (-100, "A") != 1)
1383 return 4;
1384 return 0;
1387 static int test_0_array_get_set_soft_float () {
1388 float[,] arr = new float [2, 2];
1389 arr [0, 0] = 256f;
1390 return arr [0, 0] == 256f ? 0 : 1;
1393 //repro for #506915
1394 struct Bug506915 { public int val; }
1395 static int test_2_ldobj_stobj_optization ()
1397 int i = 99;
1398 var a = new Bug506915 ();
1399 var b = new Bug506915 ();
1400 if (i.GetHashCode () == 99)
1401 i = 44;
1402 var array = new Bug506915 [2];
1403 array [0].val = 2;
1404 array [1] = (i == 0) ? a : array [0];
1406 return array [1].val;
1409 /* mcs can't compile this (#646744) */
1410 #if FALSE
1411 static void InitMe (out Gamma noMercyWithTheStack) {
1412 noMercyWithTheStack = new Gamma ();
1415 static int FunNoInline () {
1416 int x = 99;
1417 if (x > 344 && x < 22)
1418 return 333;
1419 return x;
1422 static float DoNothingButDontInline (float a, int b) {
1423 if (b > 0)
1424 return a;
1425 else if (b < 0 && b > 10)
1426 return 444.0f;
1427 return a;
1431 * The local register allocator emits loadr8_membase and storer8_membase
1432 * to do spilling. This code is generated after mono_arch_lowering_pass so
1433 * mono_arch_output_basic_block must know how to deal with big offsets.
1434 * This only happens because the call in middle forces the temp for "(float)obj"
1435 * to be spilled.
1437 public static int test_0_float_load_and_store_with_big_offset ()
1439 object obj = 1.0f;
1440 Gamma noMercyWithTheStack;
1441 float res;
1443 InitMe (out noMercyWithTheStack);
1445 res = DoNothingButDontInline ((float)obj, FunNoInline ());
1447 if (!(res == 1.0f))
1448 return 1;
1449 return 0;
1451 #endif
1453 struct VTypePhi {
1454 public int i;
1457 static int vtype_phi (VTypePhi v1, VTypePhi v2, bool first) {
1458 VTypePhi v = first ? v1 : v2;
1460 return v.i;
1463 static int test_0_vtype_phi ()
1465 VTypePhi v1 = new VTypePhi () { i = 1 };
1466 VTypePhi v2 = new VTypePhi () { i = 2 };
1468 if (vtype_phi (v1, v2, true) != 1)
1469 return 1;
1470 if (vtype_phi (v1, v2, false) != 2)
1471 return 2;
1473 return 0;
1476 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1477 static void UseValue (int index)
1481 [MethodImplAttribute (MethodImplOptions.NoInlining)]
1482 static bool IsFalse ()
1484 return false;
1487 static int test_0_llvm_moving_faulting_loads ()
1489 int[] indexes = null;
1491 if (IsFalse ()) {
1492 indexes = new int[0];
1495 while (IsFalse ()) {
1496 UseValue (indexes[0]);
1497 UseValue (indexes[0]);
1500 return 0;