Merge pull request #2810 from kumpera/fix_hazard_free
[mono.git] / mono / mini / gshared.cs
index ea146bda57d13777695b38460d3fa0c067173748..88f8c2ebb22b780a3c461daf2d8b62e6370f3e68 100644 (file)
@@ -48,13 +48,13 @@ class GFoo3<T> {
 
 // FIXME: Add mixed ref/noref tests, i.e. Dictionary<string, int>
 
-#if MOBILE
+#if __MOBILE__
 public class GSharedTests
 #else
 public class Tests
 #endif
 {
-#if !MOBILE
+#if !__MOBILE__
        public static int Main (String[] args) {
                return TestDriver.RunTests (typeof (Tests), args);
        }
@@ -464,6 +464,21 @@ public class Tests
                return 0;
        }
 
+       class DelClass {
+               [MethodImplAttribute (MethodImplOptions.NoInlining)]
+               public static T return_t<T> (T t) {
+                       return t;
+               }
+       }
+
+       public static int test_0_gsharedvt_in_delegates_reflection () {
+               var m = typeof(DelClass).GetMethod ("return_t").MakeGenericMethod (new Type [] { typeof (int) });
+               Func<int, int> f = (Func<int, int>)Delegate.CreateDelegate (typeof (Func<int,int>), null, m, false);
+               if (f (42) != 42)
+                       return 1;
+               return 0;
+       }
+
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        static T return2_t<T> (T t) {
                return return_t (t);
@@ -717,12 +732,33 @@ public class Tests
        }
 
        public static int test_0_gsharedvt_ginstvt_constructed_arg () {
+               {
+                       // AOT: Force a instantiation of use_kvp<long>
+                       long a = 1;
+                       var t = make_kvp (a, a);
+                       var z = use_kvp (t);
+               }
+
                IFaceKVP c = new ClassKVP ();
                if (c.do_kvp<long> (1) != 1)
                        return 1;
                return 0;
        }
 
+       public static int test_0_gsharedvt_ginstvt_constructed_arg_float () {
+               {
+                       // AOT: Force a instantiation of use_kvp<double>
+                       double a = 1;
+                       var t = make_kvp (a, a);
+                       var z = use_kvp (t);
+               }
+
+               IFaceKVP c = new ClassKVP ();
+               if (c.do_kvp<double> (1) != 1)
+                       return 1;
+               return 0;
+       }
+
        interface IGetter
        {
                T Get<T>();
@@ -1048,6 +1084,11 @@ public class Tests
                public Type gettype<T, T2>(T t, T2 t2) {
                        return t.GetType ();
                }
+
+               [MethodImplAttribute (MethodImplOptions.NoInlining)]
+               public Type gettype2<T>(T t) {
+                       return t.GetType ();
+               }
        }
 
        public static int test_0_constrained_gettype () {
@@ -1056,6 +1097,10 @@ public class Tests
                        return 1;
                if (c.gettype<string, int> ("A", 1) != typeof (string))
                        return 2;
+               /* Partial sharing */
+               var c2 = new CGetType ();
+               if (c2.gettype2<long> (1) != typeof (long))
+                       return 3;
                return 0;
        }
 
@@ -1291,6 +1336,7 @@ public class Tests
 
        interface IFaceBox {
                object box<T> (T t);
+               bool is_null<T> (T t);
        }
 
        class ClassBox : IFaceBox {
@@ -1298,6 +1344,12 @@ public class Tests
                        object o = t;
                        return o;
                }
+
+               public bool is_null<T> (T t) {
+                       if (!(default(T) == null))
+                               return false;
+                       return true;
+               }
        }
 
        public static int test_0_nullable_box () {
@@ -1320,6 +1372,15 @@ public class Tests
                return 0;
        }
 
+       public static int test_0_nullable_box_brtrue_opt () {
+               IFaceBox c = new ClassBox ();
+
+               if (c.is_null<double?> (null))
+                       return 0;
+               else
+                       return 1;
+       }
+
        interface IFaceUnbox2 {
                T unbox<T> (object o);
        }
@@ -1655,6 +1716,23 @@ public class Tests
                return 0;
        }
 
+       interface ISmallArg {
+               T foo<T> (string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8,
+                                 string s9, string s10, string s11, string s12, string s13, T t);
+       }
+
+       class SmallArgClass : ISmallArg {
+                       public T foo<T> (string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8,
+                                                        string s9, string s10, string s11, string s12, string s13, T t) {
+                               return t;
+                       }
+               }
+
+       public static int test_1_small_gsharedvt_stack_arg_ios () {
+               ISmallArg o = new SmallArgClass ();
+               return o.foo<int> ("", "", "", "", "", "", "", "", "", "", "", "", "", 1);
+       }
+
        // Passing vtype normal arguments on the stack
        public static int test_0_arm64_vtype_stack_args () {
                IFoo3<EmptyStruct> o = (IFoo3<EmptyStruct>)Activator.CreateInstance (typeof (Foo3<>).MakeGenericType (new Type [] { typeof (EmptyStruct) }));
@@ -1693,6 +1771,142 @@ public class Tests
                        return 2;
                return 0;
        }
+
+       public interface IFaceTest {
+               int iface_method ();
+       }
+
+       public interface IFaceConstrainedIFace {
+               int foo<T, T2> (ref T val) where T: IFaceTest;
+       }
+
+       class ConstrainedIFace : IFaceConstrainedIFace {
+               public int foo<T, T2> (ref T val) where T: IFaceTest {
+                       return val.iface_method ();
+               }
+       }
+
+       class ClassTest : IFaceTest {
+               public int iface_method () {
+                       return 42;
+               }
+       }
+
+       // Test constrained calls on an interface made from gsharedvt methods
+       public static int test_42_gsharedvt_constrained_iface () {
+               IFaceConstrainedIFace obj = new ConstrainedIFace ();
+               IFaceTest t = new ClassTest ();
+               return obj.foo<IFaceTest, int> (ref t);
+       }
+
+       // Sign extension tests
+       // 0x55   == 85    == 01010101
+       // 0xAA   == 170   == 10101010
+       // 0x5555 == 21845 == 0101010101010101
+       // 0xAAAA == 43690 == 1010101010101010
+       // 0x55555555 == 1431655765
+       // 0xAAAAAAAA == 2863311530
+       // 0x5555555555555555 == 6148914691236517205
+       // 0xAAAAAAAAAAAAAAAA == 12297829382473034410
+
+       public interface SEFace<T> {
+               T Copy (int a, int b, int c, int d, T t);
+       }
+
+       class SEClass<T> : SEFace<T> {
+               public T Copy (int a, int b, int c, int d, T t) {
+                       return t;
+               }
+       }
+
+       // Test extension
+       static int test_20_signextension_sbyte () {
+               Type t = typeof (sbyte);
+               object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+               var i = (SEFace<sbyte>)o;
+
+               long zz = i.Copy (1,2,3,4,(sbyte)(-0x55));
+
+               bool success = zz == -0x55;
+               return success ? 20 : 1;
+       }
+
+       static int test_20_signextension_byte () {
+               Type t = typeof (byte);
+               object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+               var i = (SEFace<byte>)o;
+
+               ulong zz = i.Copy (1,2,3,4,(byte)(0xAA));
+
+               bool success = zz == 0xAA;
+               return success ? 20 : 1;
+       }
+
+       static int test_20_signextension_short () {
+               Type t = typeof (short);
+               object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+               var i = (SEFace<short>)o;
+
+               long zz = i.Copy (1,2,3,4,(short)(-0x5555));
+
+               bool success = zz == -0x5555;
+               return success ? 20 : 1;
+       }
+
+       static int test_20_signextension_ushort () {
+               Type t = typeof (ushort);
+               object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+               var i = (SEFace<ushort>)o;
+
+               ulong zz = i.Copy (1,2,3,4,(ushort)(0xAAAA));
+
+               bool success = zz == 0xAAAA;
+               return success ? 20 : 1;
+       }
+
+       static int test_20_signextension_int () {
+               Type t = typeof (int);
+               object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+               var i = (SEFace<int>)o;
+
+               long zz = i.Copy (1,2,3,4,(int)(-0x55555555));
+
+               bool success = zz == -0x55555555;
+               return success ? 20 : 1;
+       }
+
+       static int test_20_signextension_uint () {
+               Type t = typeof (uint);
+               object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+               var i = (SEFace<uint>)o;
+
+               ulong zz = i.Copy (1,2,3,4,(uint)(0xAAAAAAAA));
+
+               bool success = zz == 0xAAAAAAAA;
+               return success ? 20 : 1;
+       }
+
+       static int test_20_signextension_long () {
+               Type t = typeof (long);
+               object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+               var i = (SEFace<long>)o;
+
+               long zz = i.Copy (1,2,3,4,(long)(-0x5555555555555555));
+
+               bool success = zz == -0x5555555555555555;
+               return success ? 20 : 1;
+       }
+
+       static int test_20_signextension_ulong () {
+               Type t = typeof (ulong);
+               object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+               var i = (SEFace<ulong>)o;
+
+               ulong zz = i.Copy (1,2,3,4,(ulong)(0xAAAAAAAAAAAAAAAA));
+
+               bool success = zz == 0xAAAAAAAAAAAAAAAA;
+               return success ? 20 : 1;
+       }
 }
 
 // #13191
@@ -1710,7 +1924,7 @@ public class MobileServiceCollection<TTable, TCol>
        }
 }
 
-#if !MOBILE
+#if !__MOBILE__
 public class GSharedTests : Tests {
 }
 #endif