[runtime] Remove all NACL support. It was unmaintained for a long time. (#4955)
[mono.git] / mono / mini / exceptions.cs
index f10b05629819f06954bb073d728a32db9c552327..07f498e628ba1812082dbf0cb1d3a12b2d86245d 100644 (file)
@@ -24,14 +24,14 @@ using System.Runtime.CompilerServices;
  * the IL code looks.
  */
 
-#if MOBILE
+#if __MOBILE__
 class ExceptionTests
 #else
 class Tests
 #endif
 {
 
-#if !MOBILE
+#if !__MOBILE__
        public static int Main (string[] args) {
                return TestDriver.RunTests (typeof (Tests), args);
        }
@@ -1462,7 +1462,6 @@ class Tests
                return 0;
        }
        
-       [Category ("NaClDisable")]
        public static int test_0_div_zero () {
                int d = 1;
                int q = 0;
@@ -1516,6 +1515,71 @@ class Tests
                return 0;
        }
 
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static void dummy () {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static int div_zero_llvm_inner (int i) {
+               try {
+                       // This call make use avoid the 'handler without invoke' restriction in the llvm backend
+                       dummy ();
+                       return 5 / i;
+               } catch (Exception ex) {
+                       return 0;
+               }
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static long div_zero_llvm_inner_long (long l) {
+               try {
+                       dummy ();
+                       return (long)5 / l;
+               } catch (Exception ex) {
+                       return 0;
+               }
+       }
+
+       public static int test_0_div_zero_llvm () {
+           long r = div_zero_llvm_inner (0);
+               if (r != 0)
+                       return 1;
+           r = div_zero_llvm_inner_long (0);
+               if (r != 0)
+                       return 2;
+               return 0;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static int div_overflow_llvm_inner (int i) {
+               try {
+                       dummy ();
+                       return Int32.MinValue / i;
+               } catch (Exception ex) {
+                       return 0;
+               }
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static long div_overflow_llvm_inner_long (long l) {
+               try {
+                       dummy ();
+                       return Int64.MinValue / l;
+               } catch (Exception ex) {
+                       return 0;
+               }
+       }
+
+       public static int test_0_div_overflow_llvm () {
+               long r = div_overflow_llvm_inner (-1);
+               if (r != 0)
+                       return 1;
+               r = div_overflow_llvm_inner_long ((long)-1);
+               if (r != 0)
+                       return 2;
+               return 0;
+       }
+
        public static int return_55 () {
                return 55;
        }
@@ -1568,7 +1632,6 @@ class Tests
                return 0;
        }
 
-       [Category ("NaClDisable")]
        public static int test_0_long_div_zero () {
                long d = 1;
                long q = 0;
@@ -2253,6 +2316,8 @@ class Tests
                Console.WriteLine ();
        }
 
+       [Category ("!INTERPRETER")]
+       [Category ("!BITCODE")]
        public static int test_0_rethrow_stacktrace () {
                // Check that rethrowing an exception preserves the original stack trace
                try {
@@ -2524,7 +2589,7 @@ class Tests
        public static int test_0_lmf_filter () {
                try {
                        // The invoke calls a runtime-invoke wrapper which has a filter clause
-#if MOBILE
+#if __MOBILE__
                        typeof (ExceptionTests).GetMethod ("lmf_filter").Invoke (null, new object [] { });
 #else
                        typeof (Tests).GetMethod ("lmf_filter").Invoke (null, new object [] { });
@@ -2730,10 +2795,145 @@ class Tests
                }
                return 1;
        }
+
+       static bool finally_called = false;
+
+       static void regress_30472 (int a, int b) {
+                       checked {
+                               try {
+                                       int sum = a + b;
+                               } finally {
+                                       finally_called = true;
+                               }
+            }
+               }
+
+       public static int test_0_regress_30472 () {
+               finally_called = false;
+               try {
+                   regress_30472 (Int32.MaxValue - 1, 2);
+               } catch (Exception ex) {
+               }
+               return finally_called ? 0 : 1;
+       }
+
+       static int array_len_1 = 1;
+
+       public static int test_0_bounds_check_negative_constant () {
+               try {
+                       byte[] arr = new byte [array_len_1];
+                       byte b = arr [-1];
+                       return 1;
+               } catch {
+               }
+               try {
+                       byte[] arr = new byte [array_len_1];
+                       arr [-1] = 1;
+                       return 2;
+               } catch {
+               }
+               return 0;
+       }
+
+       public static int test_0_string_bounds_check_negative_constant () {
+               try {
+                       string s = "A";
+                       char c = s [-1];
+                       return 1;
+               } catch {
+               }
+               return 0;
+       }
+
+       public class MyException : Exception {
+               public int marker = 0;
+               public string res = "";
+
+               public MyException (String res) {
+                       this.res = res;
+               }
+
+               public bool FilterWithoutState () {
+                       return this.marker == 0x666;
+               }
+
+               public bool FilterWithState () {
+                       bool ret = this.marker == 0x566;
+                       this.marker += 0x100;
+                       return ret;
+               }
+
+               public bool FilterWithStringState () {
+                       bool ret = this.marker == 0x777;
+                       this.res = "fromFilter_" + this.res;
+                       return ret;
+               }
+       }
+
+       public static int test_1_basic_filter_catch () {
+               try {
+                       MyException e = new MyException ("");
+                       e.marker = 0x1337;
+                       throw e;
+               } catch (MyException ex) when (ex.marker == 0x1337) {
+                       return 1;
+               }
+               return 0;
+       }
+
+       public static int test_1234_complicated_filter_catch () {
+               string res = "init";
+               try {
+                       MyException e = new MyException (res);
+                       e.marker = 0x566;
+                       try {
+                               try {
+                                       throw e;
+                               } catch (MyException ex) when (ex.FilterWithoutState ()) {
+                                       res = "WRONG_" + res;
+                               } finally {
+                                       e.marker = 0x777;
+                                       res = "innerFinally_" + res;
+                               }
+                       } catch (MyException ex) when (ex.FilterWithState ()) {
+                               res = "2ndcatch_" + res;
+                       }
+                       // "2ndcatch_innerFinally_init"
+                       // Console.WriteLine ("res1: " + res);
+                       e.res = res;
+                       throw e;
+               } catch (MyException ex) when (ex.FilterWithStringState ()) {
+                       res = "fwos_" + ex.res;
+               } finally {
+                       res = "outerFinally_" + res;
+               }
+               // Console.WriteLine ("res2: " + res);
+               return "outerFinally_fwos_fromFilter_2ndcatch_innerFinally_init" == res ? 1234 : 0;
+       }
+
+    public struct FooStruct
+    {
+        public long Part1 { get; }
+        public long Part2 { get; }
+
+        public byte Part3 { get; }
+    }
+
+    [MethodImpl( MethodImplOptions.NoInlining )]
+    private static bool ExceptionFilter( byte x, FooStruct item ) => true;
+
+       public static int test_0_filter_caller_area () {
+        try {
+            throw new Exception();
+        }
+        catch (Exception) when (ExceptionFilter (default(byte), default (FooStruct))) {
+        }
+               return 0;
+       }
 }
 
-#if !MOBILE
+#if !__MOBILE__
 class ExceptionTests : Tests
 {
 }
-#endif
\ No newline at end of file
+#endif