From c6d4f818746cef433d9ae3bfa979fecc1336fd0a Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Fri, 1 Jul 2022 04:59:19 -0700 Subject: [PATCH 1/3] Adds a test with two annotated out params for the same method. Test for https://github.com/dotnet/linker/issues/2874. --- .../DataFlow/ByRefDataflow.cs | 36 +++++++++++++++++++ .../DataFlow/MethodByRefParameterDataFlow.cs | 2 ++ 2 files changed, 38 insertions(+) diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs index a16c455e8563..977c0aad6896 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs @@ -34,6 +34,7 @@ public static void Main () PassRefToParameter (null); PointerDereference.Test (); + MultipleOutRefsToField.Test (); } [Kept] @@ -150,5 +151,40 @@ public static void Test () LocalStackAllocDeref (null); } } + + [Kept] + class MultipleOutRefsToField + { + [Kept] + [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + static Type _publicMethodsField; + + [Kept] + [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] + static Type _publicPropertiesField; + + [Kept] + static void TwoOutRefs( + [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + out Type publicMethods, + [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicProperties)] + out Type publicProperties) + { + publicMethods = null; + publicProperties = null; + } + + [Kept] + [ExpectedWarning ("IL2069")] + [ExpectedWarning ("IL2069")] + public static void Test() + { + TwoOutRefs (out _publicMethodsField, out _publicPropertiesField); + } + } } } diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs index 08e251d3f6eb..27dda5a8c947 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs @@ -190,6 +190,7 @@ class TestType { } + #region InheritsFromType class InheritsFromType : Type { public void MethodWithRefAndImplicitThis ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] ref Type type1, @@ -368,5 +369,6 @@ protected override bool IsPrimitiveImpl () throw new NotImplementedException (); } } + #endregion } } From 2d792204f9c14f282da3f11821ea339d89722f07 Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Fri, 1 Jul 2022 05:08:22 -0700 Subject: [PATCH 2/3] Formatting --- test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs index 977c0aad6896..5f34859b5bbe 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs @@ -166,7 +166,7 @@ class MultipleOutRefsToField static Type _publicPropertiesField; [Kept] - static void TwoOutRefs( + static void TwoOutRefs ( [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] out Type publicMethods, @@ -179,9 +179,9 @@ static void TwoOutRefs( } [Kept] - [ExpectedWarning ("IL2069")] - [ExpectedWarning ("IL2069")] - public static void Test() + [ExpectedWarning ("IL2069", ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2069", ProducedBy = ProducedBy.Trimmer)] + public static void Test () { TwoOutRefs (out _publicMethodsField, out _publicPropertiesField); } From 4cebaecf1d7dac9b4fa4d03631f02c817daadb8d Mon Sep 17 00:00:00 2001 From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> Date: Fri, 1 Jul 2022 05:09:42 -0700 Subject: [PATCH 3/3] Link to the relevant issue --- test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs index 5f34859b5bbe..2593eb33dafa 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs @@ -179,6 +179,7 @@ static void TwoOutRefs ( } [Kept] + // https://github.com/dotnet/linker/issues/2874 [ExpectedWarning ("IL2069", ProducedBy = ProducedBy.Trimmer)] [ExpectedWarning ("IL2069", ProducedBy = ProducedBy.Trimmer)] public static void Test ()