Merge pull request #2448 from BrzVlad/feature-cprop-opt
[mono.git] / mono / mini / aot-tests.cs
index 048ae081e4e8ef7d3d54de059a5526ddad5d5551..bd823f2b9062cce310ff2791ed9c39a5876c1d44 100644 (file)
@@ -238,6 +238,16 @@ class Tests
                public static T GetValue<T>(Nullable<T> value) where T : struct {
                        return value.Value;
                }
+
+               [MethodImplAttribute (MethodImplOptions.NoInlining)]
+               public static Nullable<T> Get<T>(T t) where T : struct {
+                       return t;
+               }
+
+               [MethodImplAttribute (MethodImplOptions.NoInlining)]
+               public static Nullable<T> GetNull<T>() where T : struct {
+                       return null;
+               }
        }
 
        [Category ("DYNCALL")]
@@ -259,6 +269,14 @@ class Tests
                var res = (int)typeof (NullableMethods).GetMethod ("GetValue").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { v });
                if (res != 42)
                        return 3;
+
+               NullableMethods.Get (42);
+               var res2 = (int?)typeof (NullableMethods).GetMethod ("Get").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { 42 });
+               if (res2 != 42)
+                       return 4;
+               res2 = (int?)typeof (NullableMethods).GetMethod ("GetNull").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { });
+               if (res2.HasValue)
+                       return 5;
                return 0;
        }
 
@@ -303,6 +321,52 @@ class Tests
                return 0;
        }
 
+       enum UInt32Enum : uint {
+               A = 1
+                       }
+
+       enum Int32Enum : int {
+               A = 1
+                       }
+
+       enum Int16Enum : short {
+               A = 1
+                       }
+
+       enum UInt16Enum : ushort {
+               A = 1
+                       }
+
+       enum Int8Enum : sbyte {
+               A = 1
+                       }
+
+       enum UInt8Enum : byte {
+               A = 1
+                       }
+
+       public static int test_0_int_enum_eq_comparer () {
+               var t1 = new Dictionary<Int32Enum, object> ();
+               t1 [Int32Enum.A] = "foo";
+
+               var t2 = new Dictionary<UInt32Enum, object> ();
+               t2 [UInt32Enum.A] = "foo";
+
+               var t3 = new Dictionary<UInt16Enum, object> ();
+               t3 [UInt16Enum.A] = "foo";
+
+               var t4 = new Dictionary<Int16Enum, object> ();
+               t4 [Int16Enum.A] = "foo";
+
+               var t5 = new Dictionary<Int8Enum, object> ();
+               t5 [Int8Enum.A] = "foo";
+
+               var t6 = new Dictionary<UInt8Enum, object> ();
+               t6 [UInt8Enum.A] = "foo";
+
+               return 0;
+       }
+
        public static int test_0_array_accessor_runtime_invoke_ref () {
                var t = typeof (string[]);
                var arr = Array.CreateInstance (typeof (string), 1);
@@ -312,4 +376,103 @@ class Tests
                        return 1;
                return 0;
        }
+
+       public static void SetArrayValue_<T> (T[] values) {
+               values.Select (x => x).ToArray ();
+       }
+
+       [Category ("GSHAREDVT")]
+       public static int test_0_delegate_invoke_wrappers_gsharedvt () {
+               var enums = new LongEnum [] { LongEnum.A };
+               SetArrayValue_ (enums);
+               return 0;
+       }
+
+       struct LargeStruct {
+               public int a, b, c, d;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static bool GetHasValue<T>(T? value) where T : struct
+       {
+               return value.HasValue;
+       }
+
+       [Category ("DYNCALL")]
+       public static int test_0_large_nullable_invoke () {
+               var s = new LargeStruct () { a = 1, b = 2, c = 3, d = 4 };
+
+               GetHasValue<LargeStruct> (s);
+
+#if __MOBILE__
+               var m = typeof(AotTests).GetMethod("GetHasValue", BindingFlags.Static | BindingFlags.Public);
+#else
+               var m = typeof(Tests).GetMethod("GetHasValue", BindingFlags.Static | BindingFlags.Public);
+#endif
+
+               Type type = typeof (LargeStruct?).GetGenericArguments () [0];
+               bool b1 = (bool)m.MakeGenericMethod (new Type[] {type}).Invoke (null, new object[] { s });
+               if (!b1)
+                       return 1;
+               bool b2 = (bool)m.MakeGenericMethod (new Type[] {type}).Invoke (null, new object[] { null });
+               if (b2)
+                       return 2;
+               return 0;
+       }
+
+       struct FpStruct {
+               public float a, b, c;
+       }
+
+       struct LargeStruct2 {
+               public FpStruct x;
+               public int a, b, c, d, e, f, g, h;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static int pass_hfa_on_stack (FpStruct s1, FpStruct s2, FpStruct s3) {
+               return (int)s3.c;
+       }
+
+       public static int test_10_arm64_hfa_on_stack_llvm () {
+               var arr = new LargeStruct2 [10, 10];
+               for (int i = 0; i < 10; ++i)
+                       for (int j = 0; j < 10; ++j)
+                               arr [i, j].x = new FpStruct ();
+
+               var s1 = new FpStruct () { a = 1, b = 1, c = 10 };
+               return pass_hfa_on_stack (s1, s1, s1);
+       }
+
+       public static int test_0_get_current_method () {
+               var m = MethodBase.GetCurrentMethod ();
+#if __MOBILE__
+               var m2 = typeof (AotTests).GetMethod ("test_0_get_current_method");
+#else
+               var m2 = typeof (Tests).GetMethod ("test_0_get_current_method");
+#endif
+               return m == m2 ? 0 : 1;
+       }
+
+       class GetCurrentMethodClass<T> {
+               [MethodImplAttribute (MethodImplOptions.NoInlining)]
+               public MethodBase get_current () {
+                       return MethodBase.GetCurrentMethod ();
+               }
+       }
+
+       public static int test_0_get_current_method_generic () {
+               var c = new GetCurrentMethodClass<string> ();
+               var m = c.get_current ();
+               var m2 = typeof (GetCurrentMethodClass<>).GetMethod ("get_current");
+               return m == m2 ? 0 : 1;
+       }
+
+       public static int test_0_array_wrappers_runtime_invoke () {
+               string[][] arr = new string [10][];
+               IEnumerable<string[]> iface = arr;
+               var m = typeof(IEnumerable<string[]>).GetMethod ("GetEnumerator");
+               m.Invoke (arr, null);
+               return 0;
+       }
 }