2005-12-11 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / objects.cs
index 8df96ca0552d4b0b0865bd694cdc5953d7a06775..ef3585213b5cdd525cb2761929933dab7f561d1a 100644 (file)
@@ -1,6 +1,7 @@
 using System;
 using System.Reflection;
 using System.Runtime.InteropServices;
+using System.Runtime.CompilerServices;
 
 /*
  * Regression tests for the mono JIT.
@@ -76,8 +77,11 @@ class Sample {
 [StructLayout ( LayoutKind.Explicit )]
 struct StructWithBigOffsets {
                [ FieldOffset(10000) ] public byte b;
+               [ FieldOffset(10001) ] public sbyte sb;
                [ FieldOffset(11000) ] public short s;
+               [ FieldOffset(11002) ] public ushort us;
                [ FieldOffset(12000) ] public uint i;
+               [ FieldOffset(12004) ] public int si;
                [ FieldOffset(13000) ] public long l;
                [ FieldOffset(14000) ] public float f;
                [ FieldOffset(15000) ] public double d;
@@ -290,15 +294,21 @@ class Tests {
                StructWithBigOffsets s2 = new StructWithBigOffsets ();
 
                s.b = 0xde;
+               s.sb = 0xe;
                s.s = 0x12de;
+               s.us = 0x12da;
                s.i = 0xdeadbeef;
+               s.si = 0xcafe;
                s.l = 0xcafebabe;
                s.f = 3.14F;
                s.d = 3.14;
 
                s2.b = s.b;
+               s2.sb = s.sb;
                s2.s = s.s;
+               s2.us = s.us;
                s2.i = s.i;
+               s2.si = s.si;
                s2.l = s.l;
                s2.f = s.f;
                s2.d = s.d;
@@ -315,6 +325,12 @@ class Tests {
                        return 5;
                if (s2.d != 3.14)
                        return 6;
+               if (s2.sb != 0xe)
+                       return 7;
+               if (s2.us != 0x12da)
+                       return 9;
+               if (s2.si != 0xcafe)
+                       return 10;
 
                return 0;
        }
@@ -724,5 +740,259 @@ class Tests {
                }
                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);
+       }               
+
+       static long position = 0;
+
+       public static int test_4_static_inc_long () {
+
+               int count = 4;
+
+               position = 0;
+
+               position += count;
+
+               return (int)position;
+       }
+
+       struct FooStruct {
+
+               public FooStruct (long l) {
+               }
+       }
+
+       static int test_0_calls_opcode_emulation () {
+               // Test that emulated opcodes do not clobber arguments already in
+               // out registers
+               checked {
+                       long val = 10000;
+                       new FooStruct (val * 10000);
+               }
+               return 0;
+       }
+
+       static int test_0_intrins_string_length () {
+               string s = "ABC";
+
+               return (s.Length == 3) ? 0 : 1;
+       }
+
+       static int test_0_intrins_string_chars () {
+               string s = "ABC";
+
+               return (s [0] == 'A' && s [1] == 'B' && s [2] == 'C') ? 0 : 1;
+       }
+
+       static int test_0_intrins_object_gettype () {
+               object o = 1;
+
+               return (o.GetType () == typeof (int)) ? 0 : 1;
+       }
+
+       static int test_0_intrins_object_gethashcode () {
+               object o = new Object ();
+
+               return (o.GetHashCode () == o.GetHashCode ()) ? 0 : 1;
+       }
+
+       class FooClass {
+       }
+
+       static int test_0_intrins_object_ctor () {
+               object o = new FooClass ();
+
+               return (o != null) ? 0 : 1;
+       }
+
+       static int test_0_intrins_array_rank () {
+               int[,] a = new int [10, 10];
+
+               return (a.Rank == 2) ? 0 : 1;
+       }
+
+       static int test_0_intrins_array_length () {
+               int[,] a = new int [10, 10];
+               Array a2 = a;
+
+               return (a2.Length == 100) ? 0 : 1;
+       }
+
+       static int test_0_intrins_runtimehelpers_offset_to_string_data () {
+               int i = RuntimeHelpers.OffsetToStringData;
+               
+               return i - i;
+       }
 }