+
+ // bug #485721
+ public static int test_0_try_inside_finally_cmov_opt () {
+ bool Reconect = false;
+
+ object o = new object ();
+
+ try {
+ }
+ catch (Exception ExCon) {
+ if (o != null)
+ Reconect = true;
+
+ try {
+ }
+ catch (Exception Last) {
+ }
+ }
+ finally {
+ if (Reconect == true) {
+ try {
+ }
+ catch (Exception ex) {
+ }
+ }
+ }
+
+ return 0;
+ }
+
+ public static int test_0_inline_throw () {
+ try {
+ inline_throw1 (5);
+ return 1;
+ } catch {
+ return 0;
+ }
+ }
+
+ // for llvm, the end bblock is unreachable
+ public static int inline_throw1 (int i) {
+ if (i == 0)
+ throw new Exception ();
+ else
+ return inline_throw2 (i);
+ }
+
+ public static int inline_throw2 (int i) {
+ throw new Exception ();
+ }
+
+ // bug #539550
+ 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;
+ }
+
+ public static void lmf_filter () {
+ try {
+ Connect ();
+ }
+ catch {
+ throw new NotImplementedException ();
+ }
+ }
+
+ public static void Connect () {
+ Stop ();
+ throw new Exception();
+ }
+
+ public static void Stop () {
+ try {
+ lock (null) {}
+ }
+ catch {
+ }
+ }
+
+ private static void do_raise () {
+ throw new System.Exception ();
+ }
+
+ private static int int_func (int i) {
+ return i;
+ }
+
+ // #559876
+ public static int test_8_local_deadce_causes () {
+ int myb = 4;
+
+ try {
+ myb = int_func (8);
+ do_raise();
+ myb = int_func (2);
+ } catch (System.Exception) {
+ return myb;
+ }
+ return 0;
+ }
+
+ public static int test_0_except_opt_two_clauses () {
+ int size;
+ size = -1;
+ uint ui = (uint)size;
+ try {
+ checked {
+ uint v = ui * (uint)4;
+ }
+ } catch (OverflowException e) {
+ return 0;
+ } catch (Exception) {
+ return 1;
+ }
+
+ return 2;
+ }
+
+ class Child
+ {
+ public virtual long Method()
+ {
+ throw new Exception();
+ }
+ }
+
+ /* #612206 */
+ public static int test_100_long_vars_in_clauses_initlocals_opt () {
+ Child c = new Child();
+ long value = 100;
+ try {
+ value = c.Method();
+ }
+ catch {}
+ return (int)value;
+ }
+
+ class A {
+ public object AnObj;
+ }
+
+ public static void DoSomething (ref object o) {
+ }
+
+ public static int test_0_ldflda_null () {
+ A a = null;
+
+ try {
+ DoSomething (ref a.AnObj);
+ } catch (NullReferenceException) {
+ return 0;
+ }
+
+ return 1;
+ }
+
+ unsafe struct Foo
+ {
+ public int i;
+
+ public static Foo* pFoo;
+ }
+
+ /* MS.NET doesn't seem to throw in this case */
+ public unsafe static int test_0_ldflda_null_pointer () {
+ int* pi = &Foo.pFoo->i;
+
+ 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;
+ }
+
+ 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;
+ }