Add a test for #2775.
[mono.git] / mcs / class / Mono.Debugger.Soft / Test / dtest-app.cs
index 758f2d3291f9786fdadd5dfe7c362fef67e8e0b8..f06e73736ee0a33d23b7289df3e3920f5c92c648 100644 (file)
@@ -29,6 +29,21 @@ public enum AnEnum {
        B= 1
 }
 
+public sealed class Tests3 {
+       public static void M1 () {
+       }
+
+       static void M2 () {
+       }
+
+       public void M3 () {
+       }
+
+       void M4 () {
+       }
+
+}
+
 [DebuggerDisplay ("Tests", Name="FOO", Target=typeof (int))]
 [DebuggerTypeProxy (typeof (Tests))]
 public class Tests2 {
@@ -99,6 +114,40 @@ public struct GStruct<T> {
        }
 }
 
+interface ITest
+{
+       void Foo ();
+       void Bar ();
+}
+
+interface ITest<T>
+{
+       void Foo ();
+       void Bar ();
+}
+
+class TestIfaces : ITest
+{
+       void ITest.Foo () {
+       }
+
+       void ITest.Bar () {
+       }
+
+       TestIfaces<int> Baz () {
+               return null;
+       }
+}
+
+class TestIfaces<T> : ITest<T>
+{
+       void ITest<T>.Foo () {
+       }
+
+       void ITest<T>.Bar () {
+       }
+}
+
 public class Tests : TestsBase
 {
 #pragma warning disable 0414
@@ -156,6 +205,8 @@ public class Tests : TestsBase
        }
 
        public static int Main (String[] args) {
+               tls_i = 42;
+
                if (args.Length > 0 && args [0] == "suspend-test")
                        /* This contains an infinite loop, so execute it conditionally */
                        suspend ();
@@ -171,8 +222,12 @@ public class Tests : TestsBase
                assembly_load ();
                invoke ();
                exceptions ();
+               exception_filter ();
                threads ();
                dynamic_methods ();
+               user ();
+               type_load ();
+               regress ();
                if (args.Length > 0 && args [0] == "domain-test")
                        /* This takes a lot of time, so execute it conditionally */
                        domains ();
@@ -243,6 +298,7 @@ public class Tests : TestsBase
                        ss6 (true);
                } catch {
                }
+               ss_regress_654694 ();
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -409,8 +465,9 @@ public class Tests : TestsBase
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void locals () {
                locals1 (null);
-               locals2 (null, 5);
+               locals2<string> (null, 5, "ABC");
                locals3 ();
+               locals6 ();
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -423,13 +480,15 @@ public class Tests : TestsBase
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
-       public static void locals2 (string[] args, int arg) {
+       public static void locals2<T> (string[] args, int arg, T t) {
                long i = 42;
                string s = "AB";
 
                for (int j = 0; j < 10; ++j) {
                        if (s != null)
                                i ++;
+                       if (t != null)
+                               i ++;
                }
        }
 
@@ -462,6 +521,59 @@ public class Tests : TestsBase
        public static void locals5 () {
        }
 
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void locals6 () {
+               int i = 0;
+               int j = 0;
+               for (i = 0; i < 10; ++i)
+                       j ++;
+               sbyte sb = 0;
+               for (i = 0; i < 10; ++i)
+                       sb ++;
+               locals6_1 ();
+               locals6_2 (j);
+               locals6_3 ();
+               locals6_4 (j);
+               locals6_5 ();
+               locals6_6 (sb);
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void locals6_1 () {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void locals6_2 (int arg) {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void locals6_3 () {
+               // Clobber all registers
+               int sum = 0, i, j, k, l, m;
+               for (i = 0; i < 100; ++i)
+                       sum ++;
+               for (j = 0; j < 100; ++j)
+                       sum ++;
+               for (k = 0; k < 100; ++k)
+                       sum ++;
+               for (l = 0; l < 100; ++l)
+                       sum ++;
+               for (m = 0; m < 100; ++m)
+                       sum ++;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void locals6_4 (int arg) {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void locals6_5 () {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void locals6_6 (int arg) {
+       }
+
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void line_numbers () {
                LineNumbers.ln1 ();
@@ -578,6 +690,14 @@ public class Tests : TestsBase
                return 42;
        }
 
+       public int? invoke_return_nullable () {
+               return 42;
+       }
+
+       public int? invoke_return_nullable_null () {
+               return null;
+       }
+
        public void invoke_type_load () {
                new Class3 ();
        }
@@ -632,6 +752,95 @@ public class Tests : TestsBase
                        o.GetType ();
                } catch (Exception) {
                }
+
+               try {
+                       exceptions2 ();
+               } catch (Exception) {
+               }
+       }
+
+       internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
+       {
+               if (dlg == null)
+                       throw new ArgumentNullException ();
+               if (dlg.Target != null)
+                       throw new ArgumentException ();
+               if (dlg.Method == null)
+                       throw new ArgumentException ();
+
+               var ret_type = dlg.Method.ReturnType;
+               var param_types = dlg.Method.GetParameters ().Select (x => x.ParameterType).ToArray ();
+
+               var dynamic = new DynamicMethod (Guid.NewGuid ().ToString (), ret_type, param_types, typeof (object), true);
+               var ig = dynamic.GetILGenerator ();
+
+               LocalBuilder retval = null;
+               if (ret_type != typeof (void))
+                       retval = ig.DeclareLocal (ret_type);
+
+               var label = ig.BeginExceptionBlock ();
+
+               for (int i = 0; i < param_types.Length; i++)
+                       ig.Emit (OpCodes.Ldarg, i);
+               ig.Emit (OpCodes.Call, dlg.Method);
+
+               if (retval != null)
+                       ig.Emit (OpCodes.Stloc, retval);
+
+               ig.Emit (OpCodes.Leave, label);
+
+               ig.BeginExceptFilterBlock ();
+
+               ig.Emit (OpCodes.Call, filter_method);
+
+               ig.BeginCatchBlock (null);
+
+               ig.Emit (OpCodes.Pop);
+
+               ig.EndExceptionBlock ();
+
+               if (retval != null)
+                       ig.Emit (OpCodes.Ldloc, retval);
+
+               ig.Emit (OpCodes.Ret);
+
+               return dynamic.CreateDelegate (dlg.GetType ());
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static void exception_filter_method () {
+               throw new InvalidOperationException ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static int exception_filter_filter (Exception exc) {
+               return 1;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void exception_filter () {
+               var method = typeof (Tests).GetMethod (
+                       "exception_filter_method", BindingFlags.NonPublic | BindingFlags.Static);
+               var filter_method = typeof (Tests).GetMethod (
+                       "exception_filter_filter", BindingFlags.NonPublic | BindingFlags.Static);
+
+               var dlg = Delegate.CreateDelegate (typeof (Action), method);
+
+               var wrapper = (Action) create_filter_delegate (dlg, filter_method);
+
+               wrapper ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static bool return_true () {
+               return true;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void exceptions2 () {
+               if (return_true ())
+                       throw new Exception ();
+               Console.WriteLine ();
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -720,6 +929,72 @@ public class Tests : TestsBase
        public static void frames_in_native () {
                Thread.Sleep (500);
        }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void string_call (string s) {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss_regress_654694 () {
+               if (true) {
+                       string h = "hi";
+                       string_call (h);
+               }
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void user () {
+               Debugger.Break ();
+
+               Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void type_load () {
+               type_load_2 ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static void type_load_2 () {
+               var c1 = new Dictionary<int, int> ();
+               c1.ToString ();
+               var c = new TypeLoadClass ();
+               c.ToString ();
+               var c2 = new TypeLoadClass2 ();
+               c2.ToString ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void regress () {
+               regress_2755 (DateTime.Now);
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static unsafe void regress_2755 (DateTime d) {
+               int* buffer = stackalloc int [128];
+
+               regress_2755_2 ();
+
+               int sum = 0;
+               for (int i = 0; i < 128; ++i)
+                       sum += buffer [i];
+
+               regress_2755_3 (sum);
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void regress_2755_2 () {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void regress_2755_3 (int sum) {
+       }
+}
+
+class TypeLoadClass {
+}
+
+class TypeLoadClass2 {
 }
 
 public class CrossDomain : MarshalByRefObject