diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs index 11881d3f7d15ba..737d99d93be908 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs @@ -440,6 +440,7 @@ protected override TypeAnnotations CreateValueFromKey(TypeDesc key) returnAnnotation = GetMemberTypesForDynamicallyAccessedMembersAttribute(reader, parameter.GetCustomAttributes()); if (returnAnnotation != DynamicallyAccessedMemberTypes.None && !IsTypeInterestingForDataflow(signature.ReturnType)) { + returnAnnotation = DynamicallyAccessedMemberTypes.None; _logger.LogWarning(method, DiagnosticId.DynamicallyAccessedMembersOnMethodReturnValueCanOnlyApplyToTypesOrStrings, method.GetDisplayName()); } } diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs index b2026100321931..1f31934d9b898b 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs @@ -9,6 +9,7 @@ using ILLink.RoslynAnalyzer.TrimAnalysis; using ILLink.Shared; using ILLink.Shared.TrimAnalysis; +using ILLink.Shared.TypeSystemProxy; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; @@ -245,12 +246,16 @@ static void VerifyDamOnMethodsMatch (SymbolAnalysisContext context, IMethodSymbo } } - if (!overrideMethod.IsStatic && overrideMethod.GetDynamicallyAccessedMemberTypes () != baseMethod.GetDynamicallyAccessedMemberTypes ()) { - var methodOrigin = origin ?? overrideMethod; - context.ReportDiagnostic (Diagnostic.Create ( - DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.DynamicallyAccessedMembersMismatchOnImplicitThisBetweenOverrides), - GetPrimaryLocation (methodOrigin.Locations), - overrideMethod.GetDisplayName (), baseMethod.GetDisplayName ())); + if (!overrideMethod.IsStatic) { + var overrideMethodThisAnnotation = FlowAnnotations.GetMethodParameterAnnotation (new ParameterProxy (new (overrideMethod), (ParameterIndex) 0)); + var baseMethodThisAnnotation = FlowAnnotations.GetMethodParameterAnnotation (new ParameterProxy (new (baseMethod), (ParameterIndex) 0)); + if (overrideMethodThisAnnotation != baseMethodThisAnnotation) { + var methodOrigin = origin ?? overrideMethod; + context.ReportDiagnostic (Diagnostic.Create ( + DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.DynamicallyAccessedMembersMismatchOnImplicitThisBetweenOverrides), + GetPrimaryLocation (methodOrigin.Locations), + overrideMethod.GetDisplayName (), baseMethod.GetDisplayName ())); + } } } @@ -274,7 +279,9 @@ static void VerifyDamOnInterfaceAndImplementationMethodsMatch (SymbolAnalysisCon static void VerifyDamOnPropertyAndAccessorMatch (SymbolAnalysisContext context, IMethodSymbol methodSymbol) { if ((methodSymbol.MethodKind != MethodKind.PropertyGet && methodSymbol.MethodKind != MethodKind.PropertySet) - || (methodSymbol.AssociatedSymbol?.GetDynamicallyAccessedMemberTypes () == DynamicallyAccessedMemberTypes.None)) + || methodSymbol.AssociatedSymbol is not IPropertySymbol propertySymbol + || !propertySymbol.Type.IsTypeInterestingForDataflow (isByRef: propertySymbol.RefKind is not RefKind.None) + || propertySymbol.GetDynamicallyAccessedMemberTypes () == DynamicallyAccessedMemberTypes.None) return; // None on the return type of 'get' matches unannotated @@ -283,11 +290,10 @@ static void VerifyDamOnPropertyAndAccessorMatch (SymbolAnalysisContext context, // None on parameter of 'set' matches unannotated || methodSymbol.MethodKind == MethodKind.PropertySet && methodSymbol.Parameters[methodSymbol.Parameters.Length - 1].GetDynamicallyAccessedMemberTypes () != DynamicallyAccessedMemberTypes.None) { - var associatedSymbol = methodSymbol.AssociatedSymbol!; context.ReportDiagnostic (Diagnostic.Create ( DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.DynamicallyAccessedMembersConflictsBetweenPropertyAndAccessor), - GetPrimaryLocation (associatedSymbol.Locations), - associatedSymbol.GetDisplayName (), + GetPrimaryLocation (propertySymbol.Locations), + propertySymbol.GetDisplayName (), methodSymbol.GetDisplayName () )); return; diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs index 3f1903ba12ceec..f5ff0e8a8fe549 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs @@ -47,6 +47,12 @@ internal static IEnumerable GetAttributes (this ISymbol member, s } } + /// + /// Gets DynamicallyAccessedMemberTypes for any DynamicallyAccessedMembers annotation on the symbol. + /// This doesn't validate whether the annotation is valid based on the type of the annotated symbol. + /// Use FlowAnnotations.Get*Annotation when getting annotations that are valid and should participate + /// in dataflow analysis. + /// internal static DynamicallyAccessedMemberTypes GetDynamicallyAccessedMemberTypes (this ISymbol symbol) { if (!TryGetAttribute (symbol, DynamicallyAccessedMembersAnalyzer.DynamicallyAccessedMembersAttribute, out var dynamicallyAccessedMembers)) diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FieldValue.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FieldValue.cs index c1607472b02542..cf2605ef6a21b0 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FieldValue.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FieldValue.cs @@ -15,11 +15,12 @@ public FieldValue (IFieldSymbol fieldSymbol) { FieldSymbol = fieldSymbol; StaticType = new (fieldSymbol.Type); + DynamicallyAccessedMemberTypes = FlowAnnotations.GetFieldAnnotation (fieldSymbol); } public readonly IFieldSymbol FieldSymbol; - public override DynamicallyAccessedMemberTypes DynamicallyAccessedMemberTypes => FieldSymbol.GetDynamicallyAccessedMemberTypes (); + public override DynamicallyAccessedMemberTypes DynamicallyAccessedMemberTypes { get; } public override IEnumerable GetDiagnosticArgumentsForAnnotationMismatch () => new string[] { FieldSymbol.GetDisplayName () }; diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs index c657c7cc6358bc..88a3b0250183cf 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/FlowAnnotations.cs @@ -104,7 +104,15 @@ static bool HasParameterAnnotation (IMethodSymbol method) { static bool ShouldWarnWhenAccessedForReflection (IFieldSymbol field) { - return field.GetDynamicallyAccessedMemberTypes () != DynamicallyAccessedMemberTypes.None; + return GetFieldAnnotation (field) != DynamicallyAccessedMemberTypes.None; + } + + internal static DynamicallyAccessedMemberTypes GetFieldAnnotation (IFieldSymbol field) + { + if (!field.OriginalDefinition.Type.IsTypeInterestingForDataflow (isByRef: field.RefKind is not RefKind.None)) + return DynamicallyAccessedMemberTypes.None; + + return field.GetDynamicallyAccessedMemberTypes (); } internal static DynamicallyAccessedMemberTypes GetTypeAnnotations (INamedTypeSymbol type) @@ -128,11 +136,17 @@ internal static DynamicallyAccessedMemberTypes GetTypeAnnotations (INamedTypeSym internal static DynamicallyAccessedMemberTypes GetMethodParameterAnnotation (ParameterProxy param) { - IMethodSymbol method = param.Method.Method; - if (param.IsImplicitThis) - return method.GetDynamicallyAccessedMemberTypes (); + if (param.IsImplicitThis) { + if (!param.Method.Method.ContainingType.IsTypeInterestingForDataflow (isByRef: false)) + return DynamicallyAccessedMemberTypes.None; + return param.Method.Method.GetDynamicallyAccessedMemberTypes (); + } IParameterSymbol parameter = param.ParameterSymbol!; + bool isByRef = parameter.RefKind is not RefKind.None; + if (!parameter.OriginalDefinition.Type.IsTypeInterestingForDataflow (isByRef)) + return DynamicallyAccessedMemberTypes.None; + var damt = parameter.GetDynamicallyAccessedMemberTypes (); var parameterMethod = (IMethodSymbol) parameter.ContainingSymbol; @@ -155,6 +169,9 @@ internal static DynamicallyAccessedMemberTypes GetMethodParameterAnnotation (Par public static DynamicallyAccessedMemberTypes GetMethodReturnValueAnnotation (IMethodSymbol method) { + if (!method.OriginalDefinition.ReturnType.IsTypeInterestingForDataflow (isByRef: method.ReturnsByRef)) + return DynamicallyAccessedMemberTypes.None; + var returnDamt = method.GetDynamicallyAccessedMemberTypesOnReturnType (); // Is this a property getter? diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/ReflectionAccessAnalyzer.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/ReflectionAccessAnalyzer.cs index 922c64b4e44220..506a4912d9d9d0 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/ReflectionAccessAnalyzer.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/ReflectionAccessAnalyzer.cs @@ -191,7 +191,7 @@ void GetDiagnosticsForField (Location location, IFieldSymbol fieldSymbol) if (fieldSymbol.TryGetRequiresUnreferencedCodeAttribute (out var requiresUnreferencedCodeAttributeData)) ReportRequiresUnreferencedCodeDiagnostic (location, requiresUnreferencedCodeAttributeData, fieldSymbol); - if (fieldSymbol.GetDynamicallyAccessedMemberTypes () != DynamicallyAccessedMemberTypes.None) { + if (FlowAnnotations.GetFieldAnnotation (fieldSymbol) != DynamicallyAccessedMemberTypes.None) { var diagnosticContext = new DiagnosticContext (location, _reportDiagnostic); diagnosticContext.AddDiagnostic (DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, fieldSymbol.GetDisplayName ()); } diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs index 58c3c97c550202..95ab7f31e08cdd 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs @@ -147,7 +147,7 @@ public override MultiValue VisitInstanceReference (IInstanceReferenceOperation i // It can also happen that we see this for a static method - for example a delegate creation // over a local function does this, even thought the "this" makes no sense inside a static scope. if (OwningSymbol is IMethodSymbol method && !method.IsStatic) - return new MethodParameterValue (method, (ParameterIndex) 0, method.GetDynamicallyAccessedMemberTypes ()); + return new MethodParameterValue (method, (ParameterIndex) 0, FlowAnnotations.GetMethodParameterAnnotation (new ParameterProxy (new (method), (ParameterIndex) 0))); return TopValue; } diff --git a/src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs b/src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs index b49d8628bcedb2..c7be219c42ff5f 100644 --- a/src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs +++ b/src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs @@ -253,6 +253,7 @@ TypeAnnotations BuildTypeAnnotations (TypeDefinition type) DynamicallyAccessedMemberTypes returnAnnotation = GetMemberTypesForDynamicallyAccessedMembersAttribute (method, providerIfNotMember: method.MethodReturnType); if (returnAnnotation != DynamicallyAccessedMemberTypes.None && !IsTypeInterestingForDataflow (method.ReturnType)) { + returnAnnotation = DynamicallyAccessedMemberTypes.None; _context.LogWarning (method, DiagnosticId.DynamicallyAccessedMembersOnMethodReturnValueCanOnlyApplyToTypesOrStrings, method.GetDisplayName ()); } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs index b6d5eed8170f16..99831466c3a3dc 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs @@ -170,7 +170,6 @@ class AttributeRequiresTypeArrayAttribute : Attribute { [Kept] [ExpectedWarning ("IL2098")] - [UnexpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] public AttributeRequiresTypeArrayAttribute ( [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] @@ -191,7 +190,6 @@ static void RequirePublicFields ( [Kept] [KeptAttributeAttribute (typeof (AttributeRequiresTypeArrayAttribute))] - [UnexpectedWarning ("IL2062", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] [AttributeRequiresTypeArray (new Type[] { typeof (int) })] public static void Test () { typeof (AnnotationOnTypeArray).GetMethod ("Test").GetCustomAttribute (typeof (AttributeRequiresTypeArrayAttribute)); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs index 677d2f9baae52d..ac81111bf43ccd 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs @@ -338,13 +338,11 @@ static void RequirePublicFields ( { } - [UnexpectedWarning ("IL2077", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestFlowOutOfField () { RequirePublicFields (unsupportedTypeInstance); } - [UnexpectedWarning ("IL2074", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestUnsupportedType () { var t = GetUnsupportedTypeInstance (); unsupportedTypeInstance = t; @@ -357,7 +355,6 @@ ref struct StringRef [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] public ref string stringRef; - [UnexpectedWarning ("IL2069", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] public StringRef (ref string s) { stringRef = ref s; @@ -372,7 +369,6 @@ static void RequirePublicFields ( { } - [UnexpectedWarning ("IL2077", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] void TestFlowOutOfField () { RequirePublicFields (ref stringRef); @@ -386,10 +382,23 @@ public static void Test () } } + class GenericField + { + [ExpectedWarning ("IL2097")] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + public static T field; + } + + static void TestTypeGenericParameter () + { + GenericField.field = GetUnknownType (); + } + public static void Test () { TestUnsupportedType (); StringRef.Test (); + TestTypeGenericParameter (); } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs index 01ead5a86c16d7..9f972ec37b1d17 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs @@ -246,7 +246,6 @@ class UnsupportedType static UnsupportedType GetUnsupportedTypeInstance () => null; [ExpectedWarning ("IL2098", nameof (UnsupportedType))] - [UnexpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void RequirePublicMethods ( [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] UnsupportedType unsupportedTypeInstance) @@ -261,7 +260,6 @@ static void RequirePublicFields ( { } - [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestUnsupportedType () { var t = GetUnsupportedTypeInstance (); @@ -271,7 +269,6 @@ static void TestUnsupportedType () static Type[] GetTypeArray () => null; [ExpectedWarning ("IL2098")] - [UnexpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void RequirePublicMethods ( [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type[] types) @@ -286,7 +283,6 @@ static void RequirePublicFields ( { } - [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestTypeArray () { var types = GetTypeArray (); @@ -296,7 +292,6 @@ static void TestTypeArray () static unsafe Type* GetTypePtr () => throw null; [ExpectedWarning ("IL2098")] - [UnexpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static unsafe void RequirePublicMethods ( [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type* typePtr) @@ -311,7 +306,6 @@ static unsafe void RequirePublicFields ( { } - [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static unsafe void TestTypePointer () { var typePtr = GetTypePtr (); @@ -321,7 +315,6 @@ static unsafe void TestTypePointer () static T GetTConstrainedToType () where T : Type => throw null; [ExpectedWarning ("IL2098")] - [UnexpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void RequirePublicMethods ( [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] T t) where T : Type @@ -336,7 +329,6 @@ static void RequirePublicFields ( { } - [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestTypeGenericParameter () { var t = GetTConstrainedToType (); @@ -346,7 +338,6 @@ static void TestTypeGenericParameter () static ref string GetStringRef () => throw null; [ExpectedWarning ("IL2098")] - [UnexpectedWarning ("IL2067", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void RequirePublicMethods ( [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] ref string stringRef) @@ -361,7 +352,6 @@ static void RequirePublicFields ( { } - [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestStringRef () { var stringRef = GetStringRef (); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs index abb26a1aa8e048..d1fa2f02f90934 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs @@ -190,7 +190,6 @@ class AnnotationOnUnsupportedReturnType { class UnsupportedType { - [UnexpectedWarning ("IL2082", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] public UnsupportedType () { RequirePublicFields (this); } @@ -199,9 +198,6 @@ public UnsupportedType () { static UnsupportedType GetUnsupportedTypeInstance () => null; [ExpectedWarning ("IL2106")] - // Linker and NativeAot should not produce IL2073 - // They produce dataflow warnings despite the invalid annotations. - [UnexpectedWarning ("IL2073", Tool.Trimmer | Tool.NativeAot, "https://github.com/dotnet/runtime/issues/101211")] [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] static UnsupportedType GetWithPublicMethods () { return GetUnsupportedTypeInstance (); @@ -214,13 +210,11 @@ static void RequirePublicFields ( { } - [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestMethodReturnValue () { var t = GetWithPublicMethods (); RequirePublicFields (t); } - [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestCtorReturnValue () { var t = new UnsupportedType (); RequirePublicFields (t); @@ -239,7 +233,6 @@ static void RequirePublicFields ( { } - [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] public static void Test () { var instance = new StringRefReturnValue (); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs index e33bb8e54c41a1..86fa7e15139dc8 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodThisDataFlow.cs @@ -122,7 +122,6 @@ static void RequirePublicFields ( [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] UnsupportedType unsupportedTypeInstance) { } - [UnexpectedWarning ("IL2075", nameof (UnsupportedType), nameof (UnsupportedType.GetMethod), Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] static void TestMethodThisParameter () { var t = GetUnsupportedTypeInstance (); t.GetMethod ("foo"); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs index 935db2d2aa8ab4..b41aefbce2d827 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs @@ -885,7 +885,6 @@ static void RequirePublicFields ( { } - [UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] public static void Test () { var instance = new StringRefProperty (); @@ -894,10 +893,23 @@ public static void Test () } } + [ExpectedWarning ("IL2099")] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] + static object UnsupportedPropertyAnnotationMismatch { + [ExpectedWarning ("IL2106")] + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + get; + [ExpectedWarning ("IL2098")] + [param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + set; + } + public static void Test () { _ = PropertyWithUnsupportedType; StringRefProperty.Test (); + _ = UnsupportedPropertyAnnotationMismatch; + UnsupportedPropertyAnnotationMismatch = null; } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs index ea71c1f250abf7..b56d5d0ba1918a 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs @@ -51,6 +51,8 @@ public static void Main () BaseInPreservedScope.Test (); DirectCall.Test (); RequiresAndDynamicallyAccessedMembersValidation.Test (); + InstantiatedGeneric.Test (); + AnnotationOnUnsupportedType.Test (); } static void RequirePublicMethods ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type) @@ -1075,6 +1077,44 @@ public static void Test () Test_DerivedTypeWithRequires_BaseMethodWithoutRequires (); } } + + class InstantiatedGeneric + { + class GenericBase { + [ExpectedWarning ("IL2106")] + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + public virtual T ReturnValue () => default; + } + + class InstantiatedDerived : GenericBase { + public override Type ReturnValue () => null; + } + + public static void Test () + { + new InstantiatedDerived ().ReturnValue (); + } + } + + class AnnotationOnUnsupportedType + { + class UnsupportedType { + [ExpectedWarning ("IL2041")] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + public virtual void UnsupportedAnnotationMismatch () { } + } + + class DerivedUnsupportedType : UnsupportedType { + [ExpectedWarning ("IL2041")] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] + public override void UnsupportedAnnotationMismatch () { } + } + + public static void Test () + { + new DerivedUnsupportedType ().UnsupportedAnnotationMismatch (); + } + } } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/Program.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/Program.cs index 5874fff6b0abf2..a07d41e9a32d45 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/Program.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/TopLevelStatements/InvalidAnnotations/Program.cs @@ -8,7 +8,6 @@ Test (); -[UnexpectedWarning ("IL2072", Tool.Analyzer, "https://github.com/dotnet/runtime/issues/101211")] [Kept] static void Test () { RequireAll (GetUnsupportedType ());