Switch to compiler-tester
[mono.git] / mono / mini / objects.cs
index 4344d3630db2cd29135bfd99d68fea4a30791bc9..42c5aa89e12b6fe7a3f342fadec06dd65e1c504b 100644 (file)
@@ -36,6 +36,36 @@ struct Small {
        public byte b2;
 }
 
+struct Large {
+       int one;
+       int two;
+       long three;
+       long four;
+       int five;
+       long six;
+       int seven;
+       long eight;
+       long nine;
+       long ten;
+
+       public void populate ()
+       {
+               one = 1; two = 2;
+               three = 3; four = 4;
+               five = 5; six = 6;
+               seven = 7; eight = 8;
+               nine = 9; ten = 10;
+       }
+       public bool check ()
+       {
+               return one == 1  && two == 2  &&
+                       three == 3  && four == 4  &&
+                       five == 5  && six == 6  &&
+                       seven == 7  && eight == 8  &&
+                       nine == 9  && ten == 10;
+       }
+}
+
 class Sample {
        public int a;
        public Sample (int v) {
@@ -241,8 +271,21 @@ class Tests {
                return o.GetHashCode ();
        }
 
+       static int test_0_unbox_trampoline2 () {
+               int i = 12;
+               object o = i;
+                       
+               if (i.ToString () != "12")
+                       return 1;
+               if (((Int32)o).ToString () != "12")
+                       return 2;
+               if (o.ToString () != "12")
+                       return 3;
+               return 0;
+       }
+
        // Test fields with big offsets
-       static int test_1_fields_with_big_offsets () {
+       static int test_0_fields_with_big_offsets () {
                StructWithBigOffsets s = new StructWithBigOffsets ();
                StructWithBigOffsets s2 = new StructWithBigOffsets ();
 
@@ -260,10 +303,20 @@ class Tests {
                s2.f = s.f;
                s2.d = s.d;
 
-               if ((s2.b != 0xde) || (s2.s != 0x12de) || (s2.i != 0xdeadbeef) || (s2.l != 0xcafebabe) || (s2.f != 3.14F) || (s2.d != 3.14))
-                       return 0;
-               else
+               if (s2.b != 0xde)
                        return 1;
+               if (s2.s != 0x12de)
+                       return 2;
+               if (s2.i != 0xdeadbeef)
+                       return 3;
+               if (s2.l != 0xcafebabe)
+                       return 4;
+               if (s2.f != 3.14F)
+                       return 5;
+               if (s2.d != 3.14)
+                       return 6;
+
+               return 0;
        }
 
        class TestRegA {
@@ -302,6 +355,14 @@ class Tests {
        }
        class Duper: Super {
        }
+
+       static int test_0_null_cast () {
+               object o = null;
+
+               Super s = (Super)o;
+
+               return 0;
+       }
        
        static int test_0_super_cast () {
                Duper d = new Duper ();
@@ -610,5 +671,231 @@ class Tests {
                        return 1;
                return 2;
        }
+
+       static int llmult (int a, int b, int c, int d) {
+               return a + b + c + d;
+       }
+
+       /* 
+        * Test that evaluation of complex arguments does not overwrite the
+        * arguments already in outgoing registers.
+        */
+       static int test_155_regalloc () {
+               int a = 10;
+               int b = 10;
+
+               int c = 0;
+               int d = 0;
+               int[] arr = new int [5];
+
+               return llmult (arr [c + d], 150, 5, 0);
+       }
+
+       static bool large_struct_test (Large a, Large b, Large c, Large d)
+       {
+               if (!a.check ()) return false;
+               if (!b.check ()) return false;
+               if (!c.check ()) return false;
+               if (!d.check ()) return false;
+               return true;
+       }
+
+       static int test_2_large_struct_pass ()
+       {
+               Large a, b, c, d;
+               a = new Large ();
+               b = new Large ();
+               c = new Large ();
+               d = new Large ();
+               a.populate ();
+               b.populate ();
+               c.populate ();
+               d.populate ();
+               if (large_struct_test (a, b, c, d))
+                       return 2;
+               return 0;
+       }
+
+       public static unsafe int test_0_pin_string () {
+               string x = "xxx";
+               fixed (char *c = x) {
+                       if (*c != 'x')
+                               return 1;
+               }
+               return 0;
+       }
+       
+       public static int my_flags;
+       public static int test_0_and_cmp_static ()
+       {
+               
+               /* various forms of test [mem], imm */
+               
+               my_flags = 0x01020304;
+               
+               if ((my_flags & 0x01020304) == 0)
+                       return 1;
+               
+               if ((my_flags & 0x00000304) == 0)
+                       return 2;
+               
+               if ((my_flags & 0x00000004) == 0)
+                       return 3;
+               
+               if ((my_flags & 0x00000300) == 0)
+                       return 4;
+               
+               if ((my_flags & 0x00020000) == 0)
+                       return 5;
+               
+               if ((my_flags & 0x01000000) == 0)
+                       return 6;
+               
+               return 0;
+       }
+       
+       static byte b;
+       public static int test_0_byte_compares ()
+       {
+               b = 0xff;
+               if (b == -1)
+                       return 1;
+               b = 0;
+               if (!(b < System.Byte.MaxValue))
+                       return 2;
+               
+               if (!(b <= System.Byte.MaxValue))
+                       return 3;
+               
+               return 0;
+       }
+
+       public static int test_71_long_shift_right () {
+               ulong value = 38654838087;
+               int x = 0;
+               byte [] buffer = new byte [1];
+               buffer [x] = ((byte)(value >> x));
+               return buffer [x];
+       }
+       
+       static long x;
+       public static int test_0_addsub_mem ()
+       {
+               x = 0;
+               x += 5;
+               
+               if (x != 5)
+                       return 1;
+               
+               x -= 10;
+               
+               if (x != -5)
+                       return 2;
+               
+               return 0;
+       }
+       
+       static ulong y;
+       public static int test_0_sh32_mem ()
+       {
+               y = 0x0102130405060708;
+               y >>= 32;
+               
+               if (y != 0x01021304)
+                       return 1;
+               
+               y = 0x0102130405060708;
+               y <<= 32;
+               
+               if (y != 0x0506070800000000)
+                       return 2;
+               
+               x = 0x0102130405060708;
+               x <<= 32;
+               
+               if (x != 0x0506070800000000)
+                       return 2;
+               
+               return 0;
+       }
+
+
+       static uint dum_de_dum = 1;
+       static int test_0_long_arg_opt ()
+       {
+               return Foo (0x1234567887654321, dum_de_dum);
+       }
+       
+       static int Foo (ulong x, ulong y)
+       {
+               if (x != 0x1234567887654321)
+                       return 1;
+               
+               if (y != 1)
+                       return 2;
+               
+               return 0;
+       }
+       
+       static int test_0_long_ret_opt ()
+       {
+               ulong x = X ();
+               if (x != 0x1234567887654321)
+                       return 1;
+               ulong y = Y ();
+               if (y != 1)
+                       return 2;
+               
+               return 0;
+       }
+       
+       static ulong X ()
+       {
+               return 0x1234567887654321;
+       }
+       
+       static ulong Y ()
+       {
+               return dum_de_dum;
+       }
+
+       /* from bug# 71515 */
+       static int counter = 0;
+       static bool WriteStuff () {
+               counter = 10;
+               return true;
+       }
+       static int test_0_cond_branch_side_effects () {
+               counter = 5;
+               if (WriteStuff());
+               if (counter == 10)
+                       return 0;
+               return 1;
+       }
+
+       // bug #74992
+       public static int arg_only_written (string file_name, int[]
+ncells ) {
+               if (file_name == null)
+                       return 1;
+
+               ncells = foo ();
+               bar (ncells [0]);
+
+               return 0;
+       }
+
+       public static int[] foo () {
+               return new int [3];
+       }
+
+       public static void bar (int i) {
+       }
+       
+
+       public static int test_0_arg_only_written ()
+       {
+               return arg_only_written ("md.in", null);
+       }               
 }