2007-10-19 Marek Habersack <mhabersack@novell.com>
[mono.git] / mono / mini / objects.cs
index 4a94f91987a0f66b328ac02aee7f4fd94cb48106..3bc0a03b4fc2522810433079213f6e6e6c08748f 100644 (file)
@@ -1,6 +1,8 @@
 using System;
+using System.Text;
 using System.Reflection;
 using System.Runtime.InteropServices;
+using System.Runtime.CompilerServices;
 
 /*
  * Regression tests for the mono JIT.
@@ -36,6 +38,12 @@ struct Small {
        public byte b2;
 }
 
+// Size=2, Align=1
+struct Foo {
+       bool b1;
+       bool b2;
+}
+
 struct Large {
        int one;
        int two;
@@ -76,8 +84,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;
@@ -238,17 +249,27 @@ class Tests {
                return 0;
        }
 
+       static int receive_small_sparc_many_args (int a, int a2, int a3, int a4, int a5, int a6, Small v, int b) {
+               if (v.b1 != 1)
+                       return 1;
+               if (v.b2 != 2)
+                       return 2;
+               return 0;
+       }
+
        static int test_5_pass_small_struct () {
                Small v = get_small (1);
                if (receive_small (7, v, 9) != 0)
                        return 0;
                if (receive_small (7, get_small (1), 9) != 0)
                        return 1;
+               if (receive_small_sparc_many_args (1, 2, 3, 4, 5, 6, v, 9) != 0)
+                       return 2;
                v = return_small (v);
                if (v.b1 != 1)
-                       return 2;
-               if (v.b2 != 2)
                        return 3;
+               if (v.b2 != 2)
+                       return 4;
                return 5;
        }
 
@@ -290,15 +311,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 +342,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;
        }
@@ -873,5 +906,147 @@ class Tests {
                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;
+       }
+
+       static int test_0_intrins_string_setchar () {
+               StringBuilder sb = new StringBuilder ("ABC");
+
+               sb [1] = 'D';
+
+               return sb.ToString () == "ADC" ? 0 : 1;
+       }
+
+       public class Bar {
+               bool allowLocation = true;
+        Foo f = new Foo ();    
+       }
+
+       static int test_0_regress_78990_unaligned_structs () {
+               new Bar ();
+
+               return 0;
+       }
+
+       static unsafe int test_97_negative_index () {
+               char[] arr = new char[] {'a', 'b'};
+               fixed (char *p = arr) {
+                       char *i = p + 2;
+                       char a = i[-2];
+                       return a;
+               }
+       }
+
+       /* bug #82281 */
+       static int test_0_unsigned_right_shift_imm0 () {
+               uint temp = 0;
+               byte[] data = new byte[256];
+               for (int i = 0; i < 1; i ++)
+                       temp = (uint)(data[temp >> 24] | data[temp >> 0]);
+               return 0;
+       }
 }