From 4c10cf6bd48a5405d0d04dc45f019e5b7637aa01 Mon Sep 17 00:00:00 2001 From: vitek-karas Date: Thu, 22 Oct 2020 07:12:55 -0700 Subject: [PATCH 1/2] Add test cases for complex type data flow tests Mostly array resolution issue related to https://github.com/mono/linker/pull/1566 --- .../DataFlow/ComplexTypeHandling.cs | 112 ++++++++++++++++-- 1 file changed, 104 insertions(+), 8 deletions(-) diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs index e723b6a80d6a..96a119191986 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs @@ -21,6 +21,11 @@ public static void Main () TestArrayOnGeneric (); TestGenericArray (); TestGenericArrayOnGeneric (); + TestArrayGetTypeFromMethodParam (); + TestArrayGetTypeFromField (); + TestArrayTypeGetType (); + TestArrayCreateInstanceByName (); + TestArrayInAttributeParameter (); } [Kept] @@ -52,14 +57,6 @@ static void RequirePublicMethodsOnArrayOfGeneric () RequirePublicMethods (typeof (T[])); } - [Kept] - private static void RequirePublicMethods ( - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] - [KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))] - Type type) - { - } - [Kept] class ArrayElementInGenericType { @@ -96,5 +93,104 @@ static void RequirePublicMethodsOnArrayOfGenericParameter () { _ = new RequirePublicMethodsGeneric (); } + + [Kept] + sealed class ArrayGetTypeFromMethodParamElement + { + [Kept] // This is a bug - the method should not be marked, instead Array.* should be marked + public void PublicMethod () { } + } + + [Kept] + static void TestArrayGetTypeFromMethodParamHelper(ArrayGetTypeFromMethodParamElement[] p) + { + RequirePublicMethods (p.GetType ()); + } + + [Kept] + static void TestArrayGetTypeFromMethodParam () + { + TestArrayGetTypeFromMethodParamHelper (null); + } + + [Kept] + sealed class ArrayGetTypeFromFieldElement + { + [Kept] // This is a bug - the method should not be marked, instead Array.* should be marked + public void PublicMethod () { } + } + + [Kept] + static ArrayGetTypeFromFieldElement[] _arrayGetTypeFromField; + + [Kept] + static void TestArrayGetTypeFromField () + { + RequirePublicMethods (_arrayGetTypeFromField.GetType ()); + } + + [Kept] + sealed class ArrayTypeGetTypeElement + { + [Kept] // This is a bug - the method should not be marked, instead Array.* should be marked + public void PublicMethod () { } + } + + [Kept] + static void TestArrayTypeGetType () + { + RequirePublicMethods (Type.GetType ("Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayTypeGetTypeElement[]")); + } + + [Kept] + class ArrayCreateInstanceByNameElement + { + [Kept] // This is a bug - the .ctor should not be marked - in fact in this case nothing should be marked as CreateInstance doesn't work on arrays + public ArrayCreateInstanceByNameElement() + { + } + } + + [Kept] + static void TestArrayCreateInstanceByName() + { + Activator.CreateInstance ("test", "Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayCreateInstanceByNameElement[]"); + } + + [Kept] + class ArrayInAttributeParamElement + { + [Kept] // This is a bug - the method should not be marked, instead Array.* should be marked + public void PublicMethod () { } + } + + [Kept] + [KeptAttributeAttribute(typeof(RequiresPublicMethodAttribute))] + [RequiresPublicMethod(typeof(ArrayInAttributeParamElement[]))] + static void TestArrayInAttributeParameter() + { + } + + + [Kept] + private static void RequirePublicMethods ( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + [KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))] + Type type) + { + } + + [Kept] + [KeptBaseType(typeof(Attribute))] + class RequiresPublicMethodAttribute : Attribute + { + [Kept] + public RequiresPublicMethodAttribute( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + [KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))] + Type t) + { + } + } } } From 7b5d40c1b504961fd6ba28977ef45a8b4cdbb9bf Mon Sep 17 00:00:00 2001 From: vitek-karas Date: Thu, 22 Oct 2020 07:59:36 -0700 Subject: [PATCH 2/2] Formatting --- .../DataFlow/ComplexTypeHandling.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs index 96a119191986..a86354bedcd3 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs @@ -102,7 +102,7 @@ public void PublicMethod () { } } [Kept] - static void TestArrayGetTypeFromMethodParamHelper(ArrayGetTypeFromMethodParamElement[] p) + static void TestArrayGetTypeFromMethodParamHelper (ArrayGetTypeFromMethodParamElement[] p) { RequirePublicMethods (p.GetType ()); } @@ -146,13 +146,13 @@ static void TestArrayTypeGetType () class ArrayCreateInstanceByNameElement { [Kept] // This is a bug - the .ctor should not be marked - in fact in this case nothing should be marked as CreateInstance doesn't work on arrays - public ArrayCreateInstanceByNameElement() + public ArrayCreateInstanceByNameElement () { } } [Kept] - static void TestArrayCreateInstanceByName() + static void TestArrayCreateInstanceByName () { Activator.CreateInstance ("test", "Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayCreateInstanceByNameElement[]"); } @@ -165,9 +165,9 @@ public void PublicMethod () { } } [Kept] - [KeptAttributeAttribute(typeof(RequiresPublicMethodAttribute))] - [RequiresPublicMethod(typeof(ArrayInAttributeParamElement[]))] - static void TestArrayInAttributeParameter() + [KeptAttributeAttribute (typeof (RequiresPublicMethodAttribute))] + [RequiresPublicMethod (typeof (ArrayInAttributeParamElement[]))] + static void TestArrayInAttributeParameter () { } @@ -181,11 +181,11 @@ private static void RequirePublicMethods ( } [Kept] - [KeptBaseType(typeof(Attribute))] + [KeptBaseType (typeof (Attribute))] class RequiresPublicMethodAttribute : Attribute { [Kept] - public RequiresPublicMethodAttribute( + public RequiresPublicMethodAttribute ( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] [KeptAttributeAttribute(typeof(DynamicallyAccessedMembersAttribute))] Type t)