[jit] Factor out the gsharedvt constrained call handling code into a separate function.
[mono.git] / mono / mini / exceptions.cs
index c44f0d063a39689b70c3e05db327182cd811bd2e..ed9ca4da7865dafab857618fb96e810393082620 100644 (file)
@@ -24,11 +24,18 @@ using System.Runtime.CompilerServices;
  * the IL code looks.
  */
 
-class Tests {
+#if MOBILE
+class ExceptionTests
+#else
+class Tests
+#endif
+{
 
-       public static int Main () {
-               return TestDriver.RunTests (typeof (Tests));
+#if !MOBILE
+       public static int Main (string[] args) {
+               return TestDriver.RunTests (typeof (Tests), args);
        }
+#endif
 
        public static int test_0_catch () {
                Exception x = new Exception ();
@@ -1455,6 +1462,7 @@ class Tests {
                return 0;
        }
        
+       [Category ("NaClDisable")]
        public static int test_0_div_zero () {
                int d = 1;
                int q = 0;
@@ -1560,6 +1568,7 @@ class Tests {
                return 0;
        }
 
+       [Category ("NaClDisable")]
        public static int test_0_long_div_zero () {
                long d = 1;
                long q = 0;
@@ -2240,6 +2249,8 @@ class Tests {
 
                public static void rethrow2 () {
                        rethrow1 ();
+                       /* This disables tailcall opts */
+                       Console.WriteLine ();
                }
        }
 
@@ -2307,16 +2318,6 @@ class Tests {
        public static int test_0_array_size () {
                bool failed;
 
-               try {
-                       failed = true;
-                       int[] mem1 = new int [Int32.MaxValue];
-               }
-               catch (OutOfMemoryException e) {
-                       failed = false;
-               }
-               if (failed)
-                       return 1;
-
                try {
                        failed = true;
                        int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
@@ -2342,6 +2343,8 @@ class Tests {
        }
 
        /* Test that arguments are correctly popped off the stack during unwinding */
+       /* FIXME: Fails on x86 when llvm is enabled (#5432) */
+       /*
        public static int test_0_stack_unwind () {
                addr = new IntPtr [1000];
                S s = new S ();
@@ -2354,6 +2357,26 @@ class Tests {
                }
                return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
        }
+       */
+
+       static unsafe void get_sp (int i) {
+               addr [i] = new IntPtr (&i);
+       }
+
+       /* Test that the arguments to the throw trampoline are correctly popped off the stack */
+       public static int test_0_throw_unwind () {
+               addr = new IntPtr [1000];
+               S s = new S ();
+               for (int j = 0; j < 1000; j++) {
+                       try {
+                               get_sp (j);
+                               throw new Exception ();
+                       }
+                       catch (Exception) {
+                       }
+               }
+               return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
+       }
 
        public static int test_0_regress_73242 () {
                int [] arr = new int [10];
@@ -2382,7 +2405,7 @@ class Tests {
        }
 
        public static int test_0_nonvirt_nullref_at_clause_start () {
-               Tests t = null;
+               ExceptionTests t = null;
                try {
                        t.amethod ();
                } catch (NullReferenceException) {
@@ -2502,7 +2525,11 @@ class Tests {
        public static int test_0_lmf_filter () {
                try {
                        // The invoke calls a runtime-invoke wrapper which has a filter clause
+#if MOBILE
+                       typeof (ExceptionTests).GetMethod ("lmf_filter").Invoke (null, new object [] { });
+#else
                        typeof (Tests).GetMethod ("lmf_filter").Invoke (null, new object [] { });
+#endif
                } catch (TargetInvocationException) {
                }
                return 0;
@@ -2620,5 +2647,94 @@ class Tests {
 
                return 0;
        }
+
+       static int test_0_try_clause_in_finally_clause_regalloc () {
+               // Fill up registers with values
+               object a = new object ();
+               object[] arr1 = new object [1];
+               object[] arr2 = new object [1];
+               object[] arr3 = new object [1];
+               object[] arr4 = new object [1];
+               object[] arr5 = new object [1];
+
+               for (int i = 0; i < 10; ++i)
+                       arr1 [0] = a;
+               for (int i = 0; i < 10; ++i)
+                       arr2 [0] = a;
+               for (int i = 0; i < 10; ++i)
+                       arr3 [0] = a;
+               for (int i = 0; i < 10; ++i)
+                       arr4 [0] = a;
+               for (int i = 0; i < 10; ++i)
+                       arr5 [0] = a;
+
+               int res = 1;
+               try {
+                       try_clause_in_finally_clause_regalloc_inner (out res);
+               } catch (Exception) {
+               }
+               return res;             
+       }
+
+       public static object Throw () {
+               for (int i = 0; i < 10; ++i)
+                       ;
+               throw new Exception ();
+       }
+
+       static void try_clause_in_finally_clause_regalloc_inner (out int res) {
+               object o = null;
+
+               res = 1;
+               try {
+                       o = Throw ();
+               } catch (Exception) {
+                       /* Make sure this doesn't branch to the finally */
+                       throw new DivideByZeroException ();
+               } finally {
+                       try {
+                               /* Make sure o is register allocated */
+                               if (o == null)
+                                       res = 0;
+                               else
+                                       res = 1;
+                               if (o == null)
+                                       res = 0;
+                               else
+                                       res = 1;
+                               if (o == null)
+                                       res = 0;
+                               else
+                                       res = 1;
+                       } catch (DivideByZeroException) {
+                       }
+               }
+       }
+
+    public static bool t_1835_inner () {
+        bool a = true;
+        if (a) throw new Exception();
+        return true;
+    }
+
+       [MethodImpl(MethodImplOptions.NoInlining)] 
+    public static bool t_1835_inner_2 () {
+               bool b = t_1835_inner ();
+               return b;
+       }
+
+       public static int test_0_inline_retval_throw_in_branch_1835 () {
+               try {
+                       t_1835_inner_2 ();
+               } catch {
+                       return 0;
+               }
+               return 1;
+       }
 }
 
+#if !MOBILE
+class ExceptionTests : Tests
+{
+}
+#endif
\ No newline at end of file