2 using System
.Collections
.Generic
;
4 using System
.Runtime
.CompilerServices
;
5 using System
.Threading
;
6 using System
.Threading
.Tasks
;
18 public TestStruct (int i
, int j
) {
25 class Enumerator
<T
> : MyIEnumerator
<T
> {
26 T MyIEnumerator
<T
>.Current
{
32 bool MyIEnumerator
<T
>.MoveNext () {
37 class Comparer
<T
> : IComparer
<T
> {
38 bool IComparer
<T
>.Compare (T x
, T y
) {
45 static int Main (string[] args
)
47 return TestDriver
.RunTests (typeof (Tests
), args
);
51 public static int test_1_nullable_unbox ()
53 return Unbox
<int?> (1).Value
;
56 public static int test_1_nullable_unbox_null ()
58 return Unbox
<int?> (null).HasValue
? 0 : 1;
61 public static int test_1_nullable_box ()
63 return (int) Box
<int?> (1);
66 public static int test_1_nullable_box_null ()
68 return Box
<int?> (null) == null ? 1 : 0;
71 public static int test_1_isinst_nullable ()
74 return (o
is int?) ? 1 : 0;
77 public static int test_1_nullable_unbox_vtype ()
79 return Unbox
<TestStruct
?> (new TestStruct (1, 2)).Value
.i
;
82 public static int test_1_nullable_unbox_null_vtype ()
84 return Unbox
<TestStruct
?> (null).HasValue
? 0 : 1;
87 public static int test_1_nullable_box_vtype ()
89 return ((TestStruct
)(Box
<TestStruct
?> (new TestStruct (1, 2)))).i
;
92 public static int test_1_nullable_box_null_vtype ()
94 return Box
<TestStruct
?> (null) == null ? 1 : 0;
97 public static int test_1_isinst_nullable_vtype ()
99 object o
= new TestStruct (1, 2);
100 return (o
is TestStruct
?) ? 1 : 0;
103 public static int test_0_nullable_normal_unbox ()
108 // This uses unbox instead of unbox_any
117 public static void stelem_any
<T
> (T
[] arr
, T elem
) {
121 public static T ldelem_any
<T
> (T
[] arr
) {
125 public static int test_1_ldelem_stelem_any_int () {
126 int[] arr
= new int [3];
129 return ldelem_any (arr
);
132 public static int test_1_ldelem_stelem_any_single () {
133 float[] arr
= new float [3];
136 return (int) ldelem_any (arr
);
139 public static int test_1_ldelem_stelem_any_double () {
140 double[] arr
= new double [3];
143 return (int) ldelem_any (arr
);
146 public static T return_ref
<T
> (ref T t
) {
150 public static T ldelema_any
<T
> (T
[] arr
) {
151 return return_ref
<T
> (ref arr
[0]);
154 public static int test_0_ldelema () {
155 string[] arr
= new string [1];
159 if (ldelema_any
<string> (arr
) == "Hello")
165 public static T
[,] newarr_multi
<T
> () {
169 public static int test_0_newarr_multi_dim () {
170 return newarr_multi
<string> ().GetType () == typeof (string[,]) ? 0 : 1;
178 public static int test_0_iface_call_null_bug_77442 () {
184 catch (NullReferenceException
) {
191 public static int test_18_ldobj_stobj_generics () {
192 GenericClass
<int> t
= new GenericClass
<int> ();
195 return t
.ldobj_stobj (ref i
, ref j
) + i
+ j
;
198 public static int test_5_ldelem_stelem_generics () {
199 GenericClass
<TestStruct
> t
= new GenericClass
<TestStruct
> ();
201 TestStruct s
= new TestStruct (5, 5);
202 return t
.ldelem_stelem (s
).i
;
205 public static int test_0_constrained_vtype_box () {
206 GenericClass
<TestStruct
> t
= new GenericClass
<TestStruct
> ();
209 return t
.toString (new TestStruct ()) == "GenericsTests+TestStruct" ? 0 : 1;
211 return t
.toString (new TestStruct ()) == "Tests+TestStruct" ? 0 : 1;
215 public static int test_0_constrained_vtype () {
216 GenericClass
<int> t
= new GenericClass
<int> ();
218 return t
.toString (1234) == "1234" ? 0 : 1;
221 public static int test_0_constrained_reftype () {
222 GenericClass
<String
> t
= new GenericClass
<String
> ();
224 return t
.toString ("1234") == "1234" ? 0 : 1;
227 public static int test_0_box_brtrue_optimizations () {
231 if (!IsNull
<object>(null))
237 [Category ("!FULLAOT")]
238 public static int test_0_generic_get_value_optimization_int () {
239 int[] x
= new int[] {100, 200}
;
241 if (GenericClass
<int>.Z (x
, 0) != 100)
244 if (GenericClass
<int>.Z (x
, 1) != 200)
250 interface NonGenericInterface
{
254 interface GenericInterface
<T
> : NonGenericInterface
{
258 struct ImplementGenericInterface
<T
> : GenericInterface
<T
> {
259 public Object padding1
;
260 public Object padding2
;
261 public Object padding3
;
264 public ImplementGenericInterface (T
[] arr_t
) {
265 this.padding1
= null;
266 this.padding2
= null;
267 this.padding3
= null;
271 public T
not_used () {
275 public int return_field () {
280 public static int test_8_struct_implements_generic_interface () {
281 int[] arr
= {1, 2, 3, 4}
;
282 NonGenericInterface s
= new ImplementGenericInterface
<int> (arr
);
283 return s
.return_field () + s
.return_field ();
286 public static int test_0_generic_get_value_optimization_vtype () {
287 TestStruct
[] arr
= new TestStruct
[] { new TestStruct (100, 200), new TestStruct (300, 400) }
;
288 IEnumerator
<TestStruct
> enumerator
= GenericClass
<TestStruct
>.Y (arr
);
291 while (enumerator
.MoveNext ()) {
292 s
= enumerator
.Current
;
299 s
= GenericClass
<TestStruct
>.Z (arr
, 0);
300 if (s
.i
!= 100 || s
.j
!= 200)
303 s
= GenericClass
<TestStruct
>.Z (arr
, 1);
304 if (s
.i
!= 300 || s
.j
!= 400)
310 public static int test_0_nullable_ldflda () {
311 return GenericClass
<string>.BIsAClazz
== false ? 0 : 1;
314 public struct GenericStruct
<T
> {
317 public GenericStruct (T t
) {
322 public class GenericClass
<T
> {
325 public GenericClass (T t
) {
329 public GenericClass () {
332 public T
ldobj_stobj (ref T t1
, ref T t2
) {
339 public T
ldelem_stelem (T t
) {
340 T
[] arr
= new T
[10];
346 public String
toString (T t
) {
347 return t
.ToString ();
350 public static IEnumerator
<T
> Y (IEnumerable
<T
> x
)
352 return x
.GetEnumerator ();
355 public static T
Z (IList
<T
> x
, int index
)
360 protected static T NullB
= default(T
);
361 private static Nullable
<bool> _BIsA
= null;
362 public static bool BIsAClazz
{
370 public class MRO
: MarshalByRefObject
{
371 public GenericStruct
<int> struct_field
;
372 public GenericClass
<int> class_field
;
375 public class MRO
<T
> : MarshalByRefObject
{
378 public T
stfld_ldfld (T t
) {
385 public static int test_0_ldfld_stfld_mro () {
387 GenericStruct
<int> s
= new GenericStruct
<int> (5);
388 // This generates stfld
391 // This generates ldflda
392 if (m
.struct_field
.t
!= 5)
395 // This generates ldfld
396 GenericStruct
<int> s2
= m
.struct_field
;
400 if (m
.struct_field
.t
!= 5)
403 m
.class_field
= new GenericClass
<int> (5);
404 if (m
.class_field
.t
!= 5)
408 var m2
= new MRO
<string> ();
409 if (m2
.stfld_ldfld ("A") != "A")
416 [Category ("!FULLAOT")]
417 public static int test_0_generic_virtual_call_on_vtype_unbox () {
418 object o
= new Object ();
419 IFoo h
= new Handler(o
);
421 if (h
.Bar
<object> () != o
)
427 public static int test_0_box_brtrue_opt () {
428 Foo
<int> f
= new Foo
<int> (5);
435 public static int test_0_box_brtrue_opt_regress_81102 () {
436 if (new Foo
<int>(5).ToString () == "null")
446 public static int test_0_ldloca_initobj_opt () {
447 if (new Foo
<S
> (new S ()).get_default ().i
!= 0)
449 if (new Foo
<object> (null).get_default () != null)
455 public static int test_0_variance_reflection () {
456 // covariance on IEnumerator
457 if (!typeof (MyIEnumerator
<object>).IsAssignableFrom (typeof (MyIEnumerator
<string>)))
459 // covariance on IEnumerator and covariance on arrays
460 if (!typeof (MyIEnumerator
<object>[]).IsAssignableFrom (typeof (MyIEnumerator
<string>[])))
462 // covariance and implemented interfaces
463 if (!typeof (MyIEnumerator
<object>).IsAssignableFrom (typeof (Enumerator
<string>)))
466 // contravariance on IComparer
467 if (!typeof (IComparer
<string>).IsAssignableFrom (typeof (IComparer
<object>)))
469 // contravariance on IComparer, contravariance on arrays
470 if (!typeof (IComparer
<string>[]).IsAssignableFrom (typeof (IComparer
<object>[])))
472 // contravariance and interface inheritance
473 if (!typeof (IComparer
<string>[]).IsAssignableFrom (typeof (IKeyComparer
<object>[])))
479 public static int test_0_ldvirtftn_generic_method () {
480 new GenericsTests ().ldvirtftn
<string> ();
482 return the_type
== typeof (string) ? 0 : 1;
485 public static int test_0_throw_dead_this () {
486 new Foo
<string> ("").throw_dead_this ();
492 public static int test_0_inline_infinite_polymorphic_recursion () {
498 private static void f
<T
>(int i
) {
499 if(i
==42) f
<S
<T
>>(i
);
502 // This cannot be made to work with full-aot, since there it is impossible to
503 // statically determine that Foo<string>.Bar <int> is needed, the code only
504 // references IFoo.Bar<int>
505 [Category ("!FULLAOT")]
506 public static int test_0_generic_virtual_on_interfaces () {
507 Foo
<string>.count1
= 0;
508 Foo
<string>.count2
= 0;
509 Foo
<string>.count3
= 0;
511 IFoo f
= new Foo
<string> ("");
512 for (int i
= 0; i
< 1000; ++i
) {
518 if (Foo
<string>.count1
!= 1000)
520 if (Foo
<string>.count2
!= 1000)
522 if (Foo
<string>.count3
!= 1000)
525 VirtualInterfaceCallFromGenericMethod
<long> (f
);
530 public static int test_0_generic_virtual_on_interfaces_ref () {
531 Foo
<string>.count1
= 0;
532 Foo
<string>.count2
= 0;
533 Foo
<string>.count3
= 0;
534 Foo
<string>.count4
= 0;
536 IFoo f
= new Foo
<string> ("");
537 for (int i
= 0; i
< 1000; ++i
) {
543 if (Foo
<string>.count2
!= 1000)
545 if (Foo
<string>.count3
!= 1000)
547 if (Foo
<string>.count4
!= 1000)
554 [Category ("!FULLAOT")]
555 public static int test_2_cprop_bug () {
558 var cmp
= System
.Collections
.Generic
.Comparer
<int>.Default
;
559 if (cmp
.Compare (a
, 0) > 0)
561 do { idx++; }
while (cmp
.Compare (idx
- 1, a
) == 0);
565 enum MyEnumUlong
: ulong {
569 public static int test_0_regress_550964_constrained_enum_long () {
570 MyEnumUlong a
= MyEnumUlong
.Value_2
;
571 MyEnumUlong b
= MyEnumUlong
.Value_2
;
573 return Pan (a
, b
) ? 0 : 1;
576 static bool Pan
<T
> (T a
, T b
)
581 public class XElement
{
582 public string Value
{
587 public static int test_0_fullaot_linq () {
588 var allWords
= new XElement
[] { new XElement { Value = "one" }
};
589 var filteredWords
= allWords
.Where(kw
=> kw
.Value
.StartsWith("T"));
590 return filteredWords
.Count ();
593 public static int test_0_fullaot_comparer_t () {
594 var l
= new SortedList
<TimeSpan
, int> ();
598 public static int test_0_fullaot_comparer_t_2 () {
599 var l
= new Dictionary
<TimeSpan
, int> ();
603 static void enumerate
<T
> (IEnumerable
<T
> arr
) {
604 foreach (var o
in arr
)
606 int c
= ((ICollection
<T
>)arr
).Count
;
609 /* Test that treating arrays as generic collections works with full-aot */
610 public static int test_0_fullaot_array_wrappers () {
611 GenericsTests
[] arr
= new GenericsTests
[10];
612 enumerate
<GenericsTests
> (arr
);
616 static int cctor_count
= 0;
618 public abstract class Beta
<TChanged
>
626 public class Gamma
<T
> : Beta
<T
>
634 public static int test_2_generic_class_init_gshared_ctor () {
641 static int cctor_count2
= 0;
643 class ServiceController
<T
> {
644 static ServiceController () {
648 public ServiceController () {
652 static ServiceController
<T
> Create
<T
>() {
653 return new ServiceController
<T
>();
657 public static int test_2_generic_class_init_gshared_ctor_from_gshared () {
664 public static Type get_type
<T
> () {
668 public static int test_0_gshared_delegate_rgctx () {
669 Func
<Type
> t
= new Func
<Type
> (get_type
<string>);
671 if (t () == typeof (string))
677 // Creating a delegate from a generic method from gshared code
678 public static int test_0_gshared_delegate_from_gshared () {
679 if (gshared_delegate_from_gshared
<object> () != 0)
681 if (gshared_delegate_from_gshared
<string> () != 0)
686 public static int gshared_delegate_from_gshared
<T
> () {
687 Func
<Type
> t
= new Func
<Type
> (get_type
<T
>);
689 return t () == typeof (T
) ? 0 : 1;
692 public static int test_0_marshalbyref_call_from_gshared_virt_elim () {
693 /* Calling a virtual method from gshared code which is changed to a nonvirt call */
694 Class1
<object> o
= new Class1
<object> ();
695 o
.Do (new Class2
<object> ());
699 class Pair
<TKey
, TValue
> {
700 public static KeyValuePair
<TKey
, TValue
> make_pair (TKey key
, TValue
value)
702 return new KeyValuePair
<TKey
, TValue
> (key
, value);
705 public delegate TRet Transform
<TRet
> (TKey key
, TValue
value);
708 public static int test_0_bug_620864 () {
709 var d
= new Pair
<string, Type
>.Transform
<KeyValuePair
<string, Type
>> (Pair
<string, Type
>.make_pair
);
711 var p
= d ("FOO", typeof (int));
712 if (p
.Key
!= "FOO" || p
.Value
!= typeof (int))
719 struct RecStruct
<T
> {
720 public void foo (RecStruct
<RecStruct
<T
>> baz
) {
724 public static int test_0_infinite_generic_recursion () {
725 // Check that the AOT compile can deal with infinite generic recursion through
735 bool IsNull2
<T
> (object value) where T
: struct {
736 T
? item
= (T
?) value;
744 public static int test_0_full_aot_nullable_unbox_from_gshared_code () {
745 if (!new GenericsTests ().IsNull2
<FooStruct
> (null))
747 if (new GenericsTests ().IsNull2
<FooStruct
> (new FooStruct ()))
752 public static int test_0_partial_sharing () {
753 if (PartialShared1 (new List
<string> (), 1) != typeof (string))
755 if (PartialShared1 (new List
<GenericsTests
> (), 1) != typeof (GenericsTests
))
757 if (PartialShared2 (new List
<string> (), 1) != typeof (int))
759 if (PartialShared2 (new List
<GenericsTests
> (), 1) != typeof (int))
764 [Category ("GSHAREDVT")]
765 public static int test_6_partial_sharing_linq () {
766 var messages
= new List
<Message
> ();
768 messages
.Add (new Message () { MessageID = 5 }
);
769 messages
.Add (new Message () { MessageID = 6 }
);
771 return messages
.Max(i
=> i
.MessageID
);
774 public static int test_0_partial_shared_method_in_nonshared_class () {
775 var c
= new Class1
<double> ();
776 return (c
.Foo
<string> (5).GetType () == typeof (Class1
<string>)) ? 0 : 1;
780 public int MessageID
{
785 public static Type PartialShared1
<T
, K
> (List
<T
> list
, K k
) {
789 public static Type PartialShared2
<T
, K
> (List
<T
> list
, K k
) {
793 public class Class1
<T
> {
794 public virtual void Do (Class2
<T
> t
) {
798 public virtual object Foo
<U
> (T t
) {
799 return new Class1
<U
> ();
803 public interface IFace1
<T
> {
807 public class Class2
<T
> : MarshalByRefObject
, IFace1
<T
> {
814 public static void VirtualInterfaceCallFromGenericMethod
<T
> (IFoo f
) {
818 public static Type the_type
;
820 public void ldvirtftn
<T
> () {
821 Foo
<T
> binding
= new Foo
<T
> (default (T
));
823 binding
.GenericEvent
+= event_handler
;
827 public virtual void event_handler
<T
> (Foo
<T
> sender
) {
828 the_type
= typeof (T
);
831 public interface IFoo
{
836 public class Foo
<T1
> : IFoo
843 public override string ToString()
845 return Bar(m_t1
== null ? "null" : "null");
848 public String
Bar (String s
) {
852 public int this [T1 key
] {
855 throw new ArgumentNullException ("key");
859 public void throw_dead_this () {
861 new SomeClass().ThrowAnException();
867 public T1
get_default () {
873 public delegate void GenericEventHandler (Foo
<T1
> sender
);
875 public event GenericEventHandler GenericEvent
;
877 public void fire () {
881 public static int count1
, count2
, count3
, count4
;
883 public void NonGeneric () {
887 public object Bar
<T
> () {
888 if (typeof (T
) == typeof (int))
890 else if (typeof (T
) == typeof (string))
892 else if (typeof (T
) == typeof (object))
898 public class SomeClass
{
899 public void ThrowAnException() {
900 throw new Exception ("Something went wrong");
904 struct Handler
: IFoo
{
907 public Handler(object o
) {
911 public void NonGeneric () {
914 public object Bar
<T
>() {
919 static bool IsNull
<T
> (T t
)
927 static object Box
<T
> (T t
)
932 static T Unbox
<T
> (object o
) {
936 interface IDefaultRetriever
941 class DefaultRetriever
: IDefaultRetriever
943 [MethodImpl(MethodImplOptions
.Synchronized
)]
944 public T GetDefault
<T
>()
950 [Category ("!FULLAOT")]
951 [Category ("!BITCODE")]
952 public static int test_0_regress_668095_synchronized_gshared () {
953 return DoSomething (new DefaultRetriever ());
956 static int DoSomething(IDefaultRetriever foo
) {
957 int result
= foo
.GetDefault
<int>();
962 [MethodImpl(MethodImplOptions
.Synchronized
)]
963 public Type
getInstance() {
968 [Category ("GSHAREDVT")]
969 static int test_0_synchronized_gshared () {
970 var c
= new SyncClass
<string> ();
971 if (c
.getInstance () != typeof (string))
979 public static int test_0_687865_isinst_with_cache_wrapper () {
980 object o
= new object ();
981 if (o
is Action
<IEnumerable
<Response
>>)
998 public DocType Type
{
1004 [Category ("GSHAREDVT")]
1005 public static int test_0_fullaot_sflda_cctor () {
1006 List
<Doc
> documents
= new List
<Doc
>();
1007 documents
.Add(new Doc { Name = "Doc1", Type = DocType.One }
);
1008 documents
.Add(new Doc { Name = "Doc2", Type = DocType.Two }
);
1009 documents
.Add(new Doc { Name = "Doc3", Type = DocType.Three }
);
1010 documents
.Add(new Doc { Name = "Doc4", Type = DocType.One }
);
1011 documents
.Add(new Doc { Name = "Doc5", Type = DocType.Two }
);
1012 documents
.Add(new Doc { Name = "Doc6", Type = DocType.Three }
);
1013 documents
.Add(new Doc { Name = "Doc7", Type = DocType.One }
);
1014 documents
.Add(new Doc { Name = "Doc8", Type = DocType.Two }
);
1015 documents
.Add(new Doc { Name = "Doc9", Type = DocType.Three }
);
1017 List
<DocType
> categories
= documents
.Select(d
=>d
.Type
).Distinct().ToList
<DocType
>().OrderBy(d
=> d
).ToList();
1018 foreach(DocType cat
in categories
) {
1019 List
<Doc
> catDocs
= documents
.Where(d
=> d
.Type
== cat
).OrderBy(d
=> d
.Name
).ToList
<Doc
>();
1026 static List
<A
> sources
= new List
<A
>();
1029 public static int test_0_fullaot_imt () {
1033 int a
= sources
.Count
;
1034 var enumerator
= sources
.GetEnumerator() as IEnumerator
<object>;
1036 while (enumerator
.MoveNext())
1038 object o
= enumerator
.Current
;
1047 class BClass
: AClass
{
1050 public static int test_0_fullaot_variant_iface () {
1051 var arr
= new BClass
[10];
1052 var enumerable
= (IEnumerable
<AClass
>)arr
;
1053 enumerable
.GetEnumerator ();
1057 struct Record
: Foo2
<Record
>.IRecord
{
1059 int Foo2
<Record
>.IRecord
.DoSomething () {
1064 class Foo2
<T
> where T
: Foo2
<T
>.IRecord
{
1065 public interface IRecord
{
1069 public static int Extract (T
[] t
) {
1070 return t
[0].DoSomething ();
1074 class Foo3
<T
> where T
: IComparable
{
1075 public static int CompareTo (T
[] t
) {
1076 // This is a constrained call to Enum.CompareTo ()
1077 return t
[0].CompareTo (t
[0]);
1081 public static int test_1_regress_constrained_iface_call_7571 () {
1082 var r
= new Record
[10];
1083 Foo2
<Record
>.Extract (r
);
1084 return Foo2
<Record
>.Extract (r
);
1087 enum ConstrainedEnum
{
1091 public static int test_0_regress_constrained_iface_call_enum () {
1092 var r
= new ConstrainedEnum
[10];
1093 return Foo3
<ConstrainedEnum
>.CompareTo (r
);
1096 public interface IFoo2
{
1100 public struct Foo2
: IFoo2
{
1101 public void MoveNext () {
1105 public static Action
Dingus (ref Foo2 f
) {
1106 return new Action (f
.MoveNext
);
1109 public static int test_0_delegate_unbox_full_aot () {
1110 Foo2 foo
= new Foo2 ();
1111 Dingus (ref foo
) ();
1115 public static int test_0_arrays_ireadonly () {
1116 int[] arr
= new int [10];
1117 for (int i
= 0; i
< 10; ++i
)
1119 IReadOnlyList
<int> a
= (IReadOnlyList
<int>)(object)arr
;
1129 public static int test_0_volatile_read_write () {
1131 Volatile
.Write (ref foo
, "DEF");
1132 return Volatile
.Read (ref foo
) == "DEF" ? 0 : 1;
1135 // FIXME: Doesn't work with --regression as Interlocked.Add(ref long) is only implemented as an intrinsic
1137 public static async Task
<T
> FooAsync
<T
> (int i
, int j
) {
1138 Task
<int> t
= new Task
<int> (delegate () { Console.WriteLine ("HIT!"); return 0; }
);
1139 var response
= await t
;
1143 public static int test_0_fullaot_generic_async () {
1144 Task
<string> t
= FooAsync
<string> (1, 2);
1145 t
.RunSynchronously ();
1150 public static int test_0_delegate_callvirt_fullaot () {
1151 Func
<string> f
= delegate () { return "A"; }
;
1152 var f2
= (Func
<Func
<string>, string>)Delegate
.CreateDelegate (typeof
1153 (Func
<Func
<string>, string>), null, f
.GetType ().GetMethod ("Invoke"));
1156 return s
== "A" ? 0 : 1;
1159 public interface ICovariant
<out R
>
1163 // Deleting the `out` modifier from this line stop the problem
1164 public interface IExtCovariant
<out R
> : ICovariant
<R
>
1168 public class Sample
<R
> : ICovariant
<R
>
1172 public interface IMyInterface
1176 public static int test_0_variant_cast_cache () {
1177 object covariant
= new Sample
<IMyInterface
>();
1179 var foo
= (ICovariant
<IMyInterface
>)(covariant
);
1182 var extCovariant
= (IExtCovariant
<IMyInterface
>)covariant
;
1190 public int a1
, a2
, a3
;
1193 class MyClass
<T
> where T
: struct {
1194 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1195 public MyClass(int a1
, int a2
, int a3
, int a4
, int a5
, int a6
, Nullable
<T
> a
) {
1198 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1199 public static MyClass
<T
> foo () {
1200 Nullable
<T
> a
= new Nullable
<T
> ();
1201 return new MyClass
<T
> (0, 0, 0, 0, 0, 0, a
);
1205 public static int test_0_newobj_generic_context () {
1206 MyClass
<FooStruct2
>.foo ();
1215 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1216 public static string constrained_tostring
<T
> (T t
) {
1217 return t
.ToString ();
1220 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1221 public static bool constrained_equals
<T
> (T t1
, T t2
) {
1222 var c
= EqualityComparer
<T
>.Default
;
1224 return c
.Equals (t1
, t2
);
1227 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1228 public static int constrained_gethashcode
<T
> (T t
) {
1229 return t
.GetHashCode ();
1232 public static int test_0_constrained_partial_sharing () {
1235 s
= constrained_tostring
<int> (5);
1238 s
= constrained_tostring
<AnEnum
> (AnEnum
.B
);
1242 if (!constrained_equals
<int> (1, 1))
1244 if (constrained_equals
<int> (1, 2))
1246 if (!constrained_equals
<AnEnum
> (AnEnum
.A
, AnEnum
.A
))
1248 if (constrained_equals
<AnEnum
> (AnEnum
.A
, AnEnum
.B
))
1251 int i
= constrained_gethashcode
<int> (5);
1254 i
= constrained_gethashcode
<AnEnum
> (AnEnum
.B
);
1270 public static int test_0_partial_sharing_ginst () {
1271 var l1
= new List
<KeyValuePair
<int, Enum1
>> ();
1272 l1
.Add (new KeyValuePair
<int, Enum1
>(5, Enum1
.A
));
1273 if (l1
[0].Key
!= 5)
1275 if (l1
[0].Value
!= Enum1
.A
)
1277 var l2
= new List
<KeyValuePair
<int, Enum2
>> ();
1278 l2
.Add (new KeyValuePair
<int, Enum2
>(5, Enum2
.B
));
1279 if (l2
[0].Key
!= 5)
1281 if (l2
[0].Value
!= Enum2
.B
)
1286 static object delegate_8_args_res
;
1288 public static int test_0_delegate_8_args () {
1289 delegate_8_args_res
= null;
1290 Action
<string, string, string, string, string, string, string,
1291 string> test
= (a
, b
, c
, d
, e
, f
, g
, h
) =>
1293 delegate_8_args_res
= h
;
1295 test("a", "b", "c", "d", "e", "f", "g", "h");
1296 return delegate_8_args_res
== "h" ? 0 : 1;
1299 static void throw_catch_t
<T
> () where T
: Exception
{
1301 throw new NotSupportedException ();
1306 public static int test_0_gshared_catch_open_type () {
1307 throw_catch_t
<NotSupportedException
> ();
1311 class ThrowClass
<T
> where T
: Exception
{
1312 public void throw_catch_t () {
1314 throw new NotSupportedException ();
1320 public static int test_0_gshared_catch_open_type_instance () {
1321 var c
= new ThrowClass
<NotSupportedException
> ();
1326 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1327 public static bool is_ref_or_contains_refs
<T
> () {
1328 return RuntimeHelpers
.IsReferenceOrContainsReferences
<T
> ();
1331 class IsRefClass
<T
> {
1332 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1333 public bool is_ref () {
1334 return RuntimeHelpers
.IsReferenceOrContainsReferences
<T
> ();
1338 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1339 public static bool is_ref_or_contains_refs_gen_ref
<T
> () {
1340 return RuntimeHelpers
.IsReferenceOrContainsReferences
<GenStruct
<T
>> ();
1343 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
1344 public static bool is_ref_or_contains_refs_gen_noref
<T
> () {
1345 return RuntimeHelpers
.IsReferenceOrContainsReferences
<NoRefGenStruct
<T
>> ();
1348 struct GenStruct
<T
> {
1352 struct NoRefGenStruct
<T
> {
1359 struct NestedRefStruct
{
1363 struct NoRefStruct
{
1367 struct AStruct3
<T1
, T2
, T3
> {
1373 public static int test_0_isreference_intrins () {
1374 if (RuntimeHelpers
.IsReferenceOrContainsReferences
<int> ())
1376 if (!RuntimeHelpers
.IsReferenceOrContainsReferences
<string> ())
1378 if (!RuntimeHelpers
.IsReferenceOrContainsReferences
<RefStruct
> ())
1380 if (!RuntimeHelpers
.IsReferenceOrContainsReferences
<NestedRefStruct
> ())
1382 if (RuntimeHelpers
.IsReferenceOrContainsReferences
<NoRefStruct
> ())
1385 if (is_ref_or_contains_refs
<int> ())
1388 if (!is_ref_or_contains_refs
<string> ())
1390 // Complex type from shared code
1391 if (!is_ref_or_contains_refs_gen_ref
<string> ())
1393 if (is_ref_or_contains_refs_gen_ref
<int> ())
1395 if (is_ref_or_contains_refs_gen_noref
<string> ())
1398 // Complex type from shared class method
1399 var c1
= new IsRefClass
<AStruct3
<int, int, int>> ();
1402 var c2
= new IsRefClass
<AStruct3
<string, int, int>> ();
1411 public LdobjStobj buffer1
;
1412 public LdobjStobj buffer2
;
1415 [MethodImpl(MethodImplOptions
.AggressiveInlining
)]
1416 private static void swap
<T
>(ref T first
, ref T second
) {
1420 public static int test_42_ldobj_stobj_ref () {
1421 var obj
= new LdobjStobj ();
1423 swap (ref obj
.buffer1
, ref obj
.buffer2
);
1427 public interface ICompletion
{
1428 Type
UnsafeOnCompleted ();
1431 public struct TaskAwaiter
<T
> : ICompletion
{
1432 public Type
UnsafeOnCompleted () {
1433 typeof(T
).GetHashCode ();
1438 public struct AStruct
{
1439 public Type Caller
<TAwaiter
>(ref TAwaiter awaiter
)
1440 where TAwaiter
: ICompletion
{
1441 return awaiter
.UnsafeOnCompleted();
1445 public static int test_0_partial_constrained_call_llvmonly () {
1446 var builder
= new AStruct ();
1447 var awaiter
= new TaskAwaiter
<bool> ();
1448 var res
= builder
.Caller (ref awaiter
);
1449 return res
== typeof (bool) ? 0 : 1;
1454 class GenericsTests
: Tests