Implement parity for RAF and RDC attributes in NativeAOT (#83085)
authorVitek Karas <10670590+vitek-karas@users.noreply.github.com>
Wed, 8 Mar 2023 19:20:08 +0000 (11:20 -0800)
committerGitHub <noreply@github.com>
Wed, 8 Mar 2023 19:20:08 +0000 (11:20 -0800)
The `RequiresUnreferencedCode` (RDC), `RequiresAssemblyFiles` (RAF) and `RequiresDynamicCode` (RDC) attributes should behave the same way in NativeAOT compiler. This change implements the necessary bits to make them almost 100% the same.
The only difference left is type hierarchy marking doesn't produce RAF/RDC related warnings - this is for now intentional, as it would probably produce unnecessary noise and the need for this seems to be really small.

Test changes are to basically fill in the missing expected warnings. We already have solid tests for pretty much all scenarios, they just didn't baseline these warnings since no tool produced them (illink doesn't produce RAF/RDC warnings, analyzer only produces them on direct access, not on reflection access).

This doesn't yet implement the IL3000 and IL3001 warnings in NativeAOT - that will be done in a subsequent change.

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMarker.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptionsUpdateHandler.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/VirtualMethodHierarchyDataflowAnnotationValidation.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/BasicRequires.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresAccessedThrough.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresAttributeMismatch.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnVirtualsAndInterfaces.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresViaDataflow.cs
src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresWithCopyAssembly.cs

index d7b3e3f..8a8dfd7 100644 (file)
@@ -215,17 +215,35 @@ namespace ILCompiler.Dataflow
                 }
                 else
                 {
-                    var diagnosticContext = new DiagnosticContext(
-                        origin,
-                        _logger.ShouldSuppressAnalysisWarningsForRequires(origin.MemberDefinition, DiagnosticUtilities.RequiresUnreferencedCodeAttribute),
-                        _logger.ShouldSuppressAnalysisWarningsForRequires(origin.MemberDefinition, DiagnosticUtilities.RequiresDynamicCodeAttribute),
-                        _logger.ShouldSuppressAnalysisWarningsForRequires(origin.MemberDefinition, DiagnosticUtilities.RequiresAssemblyFilesAttribute),
-                        _logger);
+                    ReportRequires(origin, entity, DiagnosticUtilities.RequiresUnreferencedCodeAttribute);
+                }
+            }
 
-                    string arg1 = MessageFormat.FormatRequiresAttributeMessageArg(DiagnosticUtilities.GetRequiresAttributeMessage(requiresAttribute.Value));
-                    string arg2 = MessageFormat.FormatRequiresAttributeUrlArg(DiagnosticUtilities.GetRequiresAttributeUrl(requiresAttribute.Value));
+            if (entity.DoesMemberRequire(DiagnosticUtilities.RequiresAssemblyFilesAttribute, out _))
+            {
+                if (_typeHierarchyDataFlowOrigin is not null)
+                {
+                    // For now we decided to not report single-file warnings due to type hierarchy marking.
+                    // It is considered too complex to figure out for the user and the likelihood of this
+                    // causing problems is pretty low.
+                }
+                else
+                {
+                    ReportRequires(origin, entity, DiagnosticUtilities.RequiresAssemblyFilesAttribute);
+                }
+            }
 
-                    diagnosticContext.AddDiagnostic(DiagnosticId.RequiresUnreferencedCode, entity.GetDisplayName(), arg1, arg2);
+            if (entity.DoesMemberRequire(DiagnosticUtilities.RequiresDynamicCodeAttribute, out _))
+            {
+                if (_typeHierarchyDataFlowOrigin is not null)
+                {
+                    // For now we decided to not report dynamic code warnings due to type hierarchy marking.
+                    // It is considered too complex to figure out for the user and the likelihood of this
+                    // causing problems is pretty low.
+                }
+                else
+                {
+                    ReportRequires(origin, entity, DiagnosticUtilities.RequiresDynamicCodeAttribute);
                 }
             }
 
@@ -258,5 +276,17 @@ namespace ILCompiler.Dataflow
                 }
             }
         }
+
+        private void ReportRequires(in MessageOrigin origin, TypeSystemEntity entity, string requiresAttributeName)
+        {
+            var diagnosticContext = new DiagnosticContext(
+                origin,
+                _logger.ShouldSuppressAnalysisWarningsForRequires(origin.MemberDefinition, DiagnosticUtilities.RequiresUnreferencedCodeAttribute),
+                _logger.ShouldSuppressAnalysisWarningsForRequires(origin.MemberDefinition, DiagnosticUtilities.RequiresDynamicCodeAttribute),
+                _logger.ShouldSuppressAnalysisWarningsForRequires(origin.MemberDefinition, DiagnosticUtilities.RequiresAssemblyFilesAttribute),
+                _logger);
+
+            ReflectionMethodBodyScanner.CheckAndReportRequires(diagnosticContext, entity, requiresAttributeName);
+        }
     }
 }
index 625a0f4..6e55938 100644 (file)
@@ -36,6 +36,7 @@ namespace ILCompiler.Dataflow
                 flowAnnotations.RequiresDataflowAnalysisDueToSignature(method) ||
                 GenericArgumentDataFlow.RequiresGenericArgumentDataFlow(flowAnnotations, method) ||
                 method.DoesMethodRequire(DiagnosticUtilities.RequiresUnreferencedCodeAttribute, out _) ||
+                method.DoesMethodRequire(DiagnosticUtilities.RequiresAssemblyFilesAttribute, out _) ||
                 method.DoesMethodRequire(DiagnosticUtilities.RequiresDynamicCodeAttribute, out _) ||
                 IsPInvokeDangerous(method, out _, out _);
         }
@@ -51,6 +52,7 @@ namespace ILCompiler.Dataflow
             return flowAnnotations.RequiresDataflowAnalysisDueToSignature(field) ||
                 GenericArgumentDataFlow.RequiresGenericArgumentDataFlow(flowAnnotations, field) ||
                 field.DoesFieldRequire(DiagnosticUtilities.RequiresUnreferencedCodeAttribute, out _) ||
+                field.DoesFieldRequire(DiagnosticUtilities.RequiresAssemblyFilesAttribute, out _) ||
                 field.DoesFieldRequire(DiagnosticUtilities.RequiresDynamicCodeAttribute, out _);
         }
 
index 57a7e14..9e1d5e4 100644 (file)
@@ -4,6 +4,7 @@
 using System.Collections.Generic;
 using System.Diagnostics.CodeAnalysis;
 using System.Reflection.Metadata;
+using System.Runtime.CompilerServices;
 using System.Text.Json;
 using System.Text.Json.Serialization.Metadata;
 
@@ -16,7 +17,6 @@ namespace System.Text.Json
     /// <summary>Handler used to clear JsonSerializerOptions reflection cache upon a metadata update.</summary>
     internal static class JsonSerializerOptionsUpdateHandler
     {
-        [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)]
         public static void ClearCache(Type[]? types)
         {
             // Ignore the types, and just clear out all reflection caches from serializer options.
@@ -25,8 +25,13 @@ namespace System.Text.Json
                 options.Key.ClearCaches();
             }
 
-            // Flush the dynamic method cache
-            ReflectionEmitCachingMemberAccessor.Clear();
+            if (RuntimeFeature.IsDynamicCodeSupported)
+            {
+                // Flush the dynamic method cache
+#pragma warning disable IL3050 // The analyzer doesn't understand runtime feature conditions: https://github.com/dotnet/linker/issues/2715
+                ReflectionEmitCachingMemberAccessor.Clear();
+#pragma warning restore IL3050
+            }
         }
     }
 }
index 2b9f2de..9b5d2f8 100644 (file)
@@ -26,6 +26,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
        {
                // The code below marks methods which have RUC on them, it's not the point of this test to validate these here
                [UnconditionalSuppressMessage ("test", "IL2026")]
+               // The code below marks methods which have RDC on them, it's not the point of this test to validate these here
+               [UnconditionalSuppressMessage ("test", "IL3050")]
                public static void Main ()
                {
                        // The test uses data flow annotation to mark all public methods on the specified types
index aeddb8f..8ccd0d7 100644 (file)
@@ -33,6 +33,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        TestRequiresFromNameOf ();
                        OnEventMethod.Test ();
                        RequiresOnGenerics.Test ();
+                       AssemblyFilesOnly.Test ();
+                       DynamicCodeOnly.Test ();
                }
 
                [ExpectedWarning ("IL2026", "Message for --RequiresWithMessageOnly--.")]
@@ -189,8 +191,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--GenericTypeWithStaticMethodWhichRequires--")]
-                       [ExpectedWarning ("IL3002", "--GenericTypeWithStaticMethodWhichRequires--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "--GenericTypeWithStaticMethodWhichRequires--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "--GenericTypeWithStaticMethodWhichRequires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--GenericTypeWithStaticMethodWhichRequires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static void GenericTypeWithStaticMethodViaLdftn ()
                        {
                                var _ = new Action (GenericWithStaticMethod<TestType>.GenericTypeWithStaticMethodWhichRequires);
@@ -207,5 +209,29 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                                MakeNew2<TestType> ();
                        }
                }
+
+               class AssemblyFilesOnly
+               {
+                       [RequiresAssemblyFiles("--Requires--")]
+                       static void Requires () { }
+
+                       [ExpectedWarning("IL3002", "--Requires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       public static void Test()
+                       {
+                               Requires ();
+                       }
+               }
+
+               class DynamicCodeOnly
+               {
+                       [RequiresDynamicCode ("--Requires--")]
+                       static void Requires () { }
+
+                       [ExpectedWarning ("IL3050", "--Requires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       public static void Test ()
+                       {
+                               Requires ();
+                       }
+               }
        }
 }
index a531f94..9ad7bc1 100644 (file)
@@ -41,7 +41,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                {
                }
 
+               // https://github.com/dotnet/linker/issues/2739 - the discussion there explains why (at least for now) we don't produce
+               // RAF and RDC warnings from the analyzer in these cases.
                [ExpectedWarning ("IL2026", "--RequiresOnlyThroughReflection--")]
+               [ExpectedWarning ("IL3002", "--RequiresOnlyThroughReflection--", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "--RequiresOnlyThroughReflection--", ProducedBy = Tool.NativeAot)]
                static void TestRequiresOnlyThroughReflection ()
                {
                        typeof (RequiresAccessedThrough)
@@ -59,6 +63,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--GenericType.RequiresOnlyThroughReflection--")]
+                       [ExpectedWarning ("IL3002", "--GenericType.RequiresOnlyThroughReflection--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--GenericType.RequiresOnlyThroughReflection--", ProducedBy = Tool.NativeAot)]
                        public static void Test ()
                        {
                                typeof (AccessedThroughReflectionOnGenericType<T>)
@@ -218,12 +224,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                                }
                        }
 
-                       // NativeAOT should produce diagnostics when using Func
-                       // https://github.com/dotnet/runtime/issues/73321
                        [ExpectedWarning ("IL2026", "--PropertyWithLdToken.get--")]
                        [ExpectedWarning ("IL2026", "--PropertyWithLdToken.get--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
-                       [ExpectedWarning ("IL3002", "--PropertyWithLdToken.get--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "--PropertyWithLdToken.get--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "--PropertyWithLdToken.get--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--PropertyWithLdToken.get--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--PropertyWithLdToken.get--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--PropertyWithLdToken.get--", ProducedBy = Tool.NativeAot)]
                        public static void Test ()
                        {
                                Expression<Func<bool>> getter = () => PropertyWithLdToken;
index 3d60cdc..e20458f 100644 (file)
@@ -23,29 +23,67 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
        {
                // Base/Derived and Implementation/Interface differs between ILLink and analyzer https://github.com/dotnet/linker/issues/2533
                [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get")]
+               [ExpectedWarning ("IL3002", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get")]
+               [ExpectedWarning ("IL3002", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get")]
+               [ExpectedWarning ("IL3002", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "BaseClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "DerivedClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "DerivedClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "DerivedClassWithRequires.VirtualPropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInAccesor.set", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInAccesor.set", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInProperty.get", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInProperty.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInProperty.set", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInProperty.set", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL2026", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInPropertyAndAccessor.set", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "DerivedClassWithAllWarnings.VirtualPropertyAnnotationInPropertyAndAccessor.set", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualMethod()")]
+               [ExpectedWarning ("IL3002", "BaseClassWithRequires.VirtualMethod()", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "BaseClassWithRequires.VirtualMethod()", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualMethod()")]
+               [ExpectedWarning ("IL3002", "BaseClassWithRequires.VirtualMethod()", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "BaseClassWithRequires.VirtualMethod()", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualMethod()")]
+               [ExpectedWarning ("IL3002", "BaseClassWithRequires.VirtualMethod()", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "BaseClassWithRequires.VirtualMethod()", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "DerivedClassWithRequires.VirtualMethod()", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "DerivedClassWithRequires.VirtualMethod()", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "DerivedClassWithRequires.VirtualMethod()", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "IBaseWithRequires.PropertyAnnotationInAccesor.get")]
-               [ExpectedWarning ("IL2026", "IBaseWithRequires.PropertyAnnotationInPropertyAndAccessor.set", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "IBaseWithRequires.PropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "IBaseWithRequires.PropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL2026", "IBaseWithRequires.PropertyAnnotationInPropertyAndAccessor.set")]
+               [ExpectedWarning ("IL3002", "IBaseWithRequires.PropertyAnnotationInPropertyAndAccessor.set", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "IBaseWithRequires.Method()")]
+               [ExpectedWarning ("IL3002", "IBaseWithRequires.Method()", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "IBaseWithRequires.Method()", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "ImplementationClassWithRequires.Method()", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "ImplementationClassWithRequires.Method()", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "ImplementationClassWithRequires.Method()", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "ImplementationClassWithRequires.PropertyAnnotationInAccesor.get", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "ImplementationClassWithRequires.PropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "ImplementationClassWithRequires.PropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "ImplementationClassWithRequires.PropertyAnnotationInPropertyAndAccessor.get", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "ImplementationClassWithRequires.PropertyAnnotationInPropertyAndAccessor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "ImplementationClassWithoutRequires.PropertyAnnotationInPropertyAndAccessor.get", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "ImplementationClassWithoutRequires.PropertyAnnotationInPropertyAndAccessor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "ImplementationClassWithRequiresInSource.Method()", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "ImplementationClassWithRequiresInSource.Method()", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "ImplementationClassWithRequiresInSource.Method()", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "ImplementationClassWithRequiresInSource.PropertyAnnotationInAccesor.get", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "ImplementationClassWithRequiresInSource.PropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "ImplementationClassWithRequiresInSource.PropertyAnnotationInAccesor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get")]
+               [ExpectedWarning ("IL3002", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get")]
+               [ExpectedWarning ("IL3002", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get")]
-               [ExpectedWarning ("IL2026", "PropertyAnnotationInPropertyAndAccessor.set")]
+               [ExpectedWarning ("IL3002", "BaseClassWithRequires.VirtualPropertyAnnotationInPropertyAndAccessor.get", ProducedBy = Tool.NativeAot)]
 
                public static void Main ()
                {
@@ -492,11 +530,23 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                class StaticInterfaceMethods
                {
                        [ExpectedWarning ("IL2026")]
+                       [ExpectedWarning ("IL3002", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026")]
+                       [ExpectedWarning ("IL3002", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026")]
+                       [ExpectedWarning ("IL3002", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026")]
+                       [ExpectedWarning ("IL3002", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026")]
+                       [ExpectedWarning ("IL3002", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026")]
+                       [ExpectedWarning ("IL3002", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", ProducedBy = Tool.NativeAot)]
                        public static void Test ()
                        {
                                typeof (IRequires).RequiresPublicMethods ();
@@ -506,6 +556,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                                typeof (ImplIRequiresMismatching).RequiresPublicMethods ();
                                typeof (ImplIRequiresMatching).RequiresPublicMethods ();
                        }
+
                        interface IRequires
                        {
                                [RequiresUnreferencedCode ("Message for --StaticInterfaceMethods.IRequires.VirtualMethod--")]
index 35b895c..039fd89 100644 (file)
@@ -67,6 +67,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+                       [ExpectedWarning ("IL3002", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
                        static IEnumerable<int> TestReflectionAccess ()
                        {
                                yield return 0;
@@ -78,6 +80,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
 #if !RELEASE
                        [ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
 #else
                        // In release mode, the compiler optimizes away the unused Action (and reference to MethodWithRequires)
 #endif
@@ -93,8 +97,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
                        // Cannot annotate fields either with RUC nor RAF therefore the warning persists
                        [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static IEnumerable<int> TestLazyDelegate ()
@@ -105,6 +109,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true)]
+                       [ExpectedWarning ("IL3002", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
                        static IEnumerable<int> TestDynamicallyAccessedMethod ()
                        {
                                typeof (TypeWithMethodWithRequires).RequiresNonPublicMethods ();
@@ -160,8 +166,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
                        // Cannot annotate fields either with RUC nor RAF therefore the warning persists
                        [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static IEnumerable<int> TestLazyDelegate ()
@@ -249,6 +255,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+                       [ExpectedWarning ("IL3002", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
                        static async void TestReflectionAccess ()
                        {
                                await MethodAsync ();
@@ -260,6 +268,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
 #if !RELEASE
                        [ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
 #endif
                        [ExpectedWarning ("IL2026", "--MethodWithRequires--", ProducedBy = Tool.Analyzer)]
                        [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = Tool.Analyzer)]
@@ -271,8 +281,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static async void TestLazyDelegate ()
@@ -282,6 +292,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true)]
+                       [ExpectedWarning ("IL3002", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
                        static async void TestDynamicallyAccessedMethod ()
                        {
                                typeof (TypeWithMethodWithRequires).RequiresNonPublicMethods ();
@@ -335,8 +347,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
                        // Cannot annotate fields either with RUC nor RAF therefore the warning persists
                        [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static async void TestLazyDelegate ()
@@ -424,6 +436,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--MethodWithRequires--", CompilerGeneratedCode = true)]
+                       [ExpectedWarning ("IL3002", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
                        static async IAsyncEnumerable<int> TestReflectionAccess ()
                        {
                                yield return 0;
@@ -437,6 +451,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
 #if !RELEASE
                        [ExpectedWarning ("IL2026", "--MethodWithRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot, CompilerGeneratedCode = true)]
+                       [ExpectedWarning ("IL3002", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
 #endif
                        [ExpectedWarning ("IL2026", "--MethodWithRequires--", ProducedBy = Tool.Analyzer)]
                        [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = Tool.Analyzer)]
@@ -449,8 +465,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static async IAsyncEnumerable<int> TestLazyDelegate ()
@@ -461,6 +477,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true)]
+                       [ExpectedWarning ("IL3002", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TypeWithMethodWithRequires.MethodWithRequires--", CompilerGeneratedCode = true, ProducedBy = Tool.NativeAot)]
                        static async IAsyncEnumerable<int> TestDynamicallyAccessedMethod ()
                        {
                                typeof (TypeWithMethodWithRequires).RequiresNonPublicMethods ();
@@ -519,8 +537,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
                        // Cannot annotate fields either with RUC nor RAF therefore the warning persists
                        [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static async IAsyncEnumerable<int> TestLazyDelegate ()
@@ -656,6 +674,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                                LocalFunction ();
 
                                [ExpectedWarning ("IL2026", "--MethodWithRequires--")]
+                               [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                               [ExpectedWarning ("IL3050", "--MethodWithRequires--", ProducedBy = Tool.NativeAot)]
                                void LocalFunction () => typeof (RequiresInCompilerGeneratedCode)
                                        .GetMethod ("MethodWithRequires", System.Reflection.BindingFlags.NonPublic)
                                        .Invoke (null, new object[] { });
@@ -667,6 +687,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
 #if !RELEASE
                                [ExpectedWarning ("IL2026", "--MethodWithRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                               [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                               [ExpectedWarning ("IL3050", "--MethodWithRequires--", ProducedBy = Tool.NativeAot)]
 #endif
                                [ExpectedWarning ("IL2026", "--MethodWithRequires--", ProducedBy = Tool.Analyzer)]
                                [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = Tool.Analyzer)]
@@ -678,8 +700,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static void TestLazyDelegate ()
@@ -697,6 +719,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                                LocalFunction ();
 
                                [ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--")]
+                               [ExpectedWarning ("IL3002", "--TypeWithMethodWithRequires.MethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                               [ExpectedWarning ("IL3050", "--TypeWithMethodWithRequires.MethodWithRequires--", ProducedBy = Tool.NativeAot)]
                                void LocalFunction () => typeof (TypeWithMethodWithRequires).RequiresNonPublicMethods ();
                        }
 
@@ -781,8 +805,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "Message from --MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static void TestLazyDelegate ()
@@ -1129,8 +1153,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--LambdaWithRequires--")]
-                       [ExpectedWarning ("IL3002", "--LambdaWithRequires--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "--LambdaWithRequires--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "--LambdaWithRequires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--LambdaWithRequires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        static void TestLambdaWithRequires ()
                        {
                                Action lambda =
@@ -1152,8 +1176,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--LambdaWithRequires--")]
-                       [ExpectedWarning ("IL3002", "--LambdaWithRequires--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "--LambdaWithRequires--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "--LambdaWithRequires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--LambdaWithRequires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        static void TestLambdaWithRequiresUnused ()
                        {
                                Action _ =
@@ -1198,6 +1222,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        {
                                Action _ =
                                [ExpectedWarning ("IL2026", "--MethodWithRequires--")]
+                               [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                               [ExpectedWarning ("IL3050", "--MethodWithRequires--", ProducedBy = Tool.NativeAot)]
                                () => {
                                        typeof (RequiresInCompilerGeneratedCode)
                                                .GetMethod ("MethodWithRequires", System.Reflection.BindingFlags.NonPublic)
@@ -1210,6 +1236,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                                Action _ =
 #if !RELEASE
                                [ExpectedWarning ("IL2026", "--MethodWithRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                               [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                               [ExpectedWarning ("IL3050", "--MethodWithRequires--", ProducedBy = Tool.NativeAot)]
 #endif
                                [ExpectedWarning ("IL2026", "--MethodWithRequires--", ProducedBy = Tool.Analyzer)]
                                [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = Tool.Analyzer)]
@@ -1220,8 +1248,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "--MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "--MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "--MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static void TestLazyDelegate ()
@@ -1235,6 +1263,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        {
                                Action _ =
                                [ExpectedWarning ("IL2026", "--TypeWithMethodWithRequires.MethodWithRequires--")]
+                               [ExpectedWarning ("IL3002", "--TypeWithMethodWithRequires.MethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                               [ExpectedWarning ("IL3050", "--TypeWithMethodWithRequires.MethodWithRequires--", ProducedBy = Tool.NativeAot)]
                                () => {
                                        typeof (TypeWithMethodWithRequires).RequiresNonPublicMethods ();
                                };
@@ -1323,8 +1353,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--MethodWithRequiresAndReturns--", CompilerGeneratedCode = true)]
-                       [ExpectedWarning ("IL3002", "--MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "--MethodWithRequiresAndReturns--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "--MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--MethodWithRequiresAndReturns--", CompilerGeneratedCode = true, ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        public static Lazy<string> _default = new Lazy<string> (MethodWithRequiresAndReturns);
 
                        static void TestLazyDelegate ()
@@ -1380,8 +1410,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026")]
-                       [ExpectedWarning ("IL3002", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        static void TestSuppressionOnLambda ()
                        {
                                var lambda =
@@ -1394,8 +1424,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026")]
-                       [ExpectedWarning ("IL3002", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        static void TestSuppressionOnLambdaWithNestedLambda ()
                        {
                                var lambda =
@@ -1409,8 +1439,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                                        // However, we don't make this association, for consistency with local functions.
                                        var nestedLambda =
                                        [ExpectedWarning ("IL2026", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
-                                       [ExpectedWarning ("IL3002", ProducedBy = Tool.NativeAot)]
-                                       [ExpectedWarning ("IL3050", ProducedBy = Tool.NativeAot)]
+                                       [ExpectedWarning ("IL3002", ProducedBy = Tool.NativeAot | Tool.NativeAot)]
+                                       [ExpectedWarning ("IL3050", ProducedBy = Tool.NativeAot | Tool.NativeAot)]
                                        () => MethodWithRequires ();
                                };
 
@@ -1862,7 +1892,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--TestIteratorOnlyReferencedViaReflectionWhichShouldSuppress--")]
+                       [ExpectedWarning ("IL3002", "--TestIteratorOnlyReferencedViaReflectionWhichShouldSuppress--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestIteratorOnlyReferencedViaReflectionWhichShouldSuppress--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestAsyncOnlyReferencedViaReflectionWhichShouldSuppress--")]
+                       [ExpectedWarning ("IL3002", "--TestAsyncOnlyReferencedViaReflectionWhichShouldSuppress--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestAsyncOnlyReferencedViaReflectionWhichShouldSuppress--", ProducedBy = Tool.NativeAot)]
                        // Analyzer doesn't emit additional warnings about reflection access to the compiler-generated
                        // state machine members.
                        [ExpectedWarning ("IL2026", "--TestIteratorOnlyReferencedViaReflectionWhichShouldSuppress--", ProducedBy = Tool.Trimmer)]
@@ -1885,7 +1919,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "--TestIteratorOnlyReferencedViaReflectionWhichShouldSuppress--")]
+                       [ExpectedWarning ("IL3002", "--TestIteratorOnlyReferencedViaReflectionWhichShouldSuppress--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestIteratorOnlyReferencedViaReflectionWhichShouldSuppress--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestAsyncOnlyReferencedViaReflectionWhichShouldSuppress--")]
+                       [ExpectedWarning ("IL3002", "--TestAsyncOnlyReferencedViaReflectionWhichShouldSuppress--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestAsyncOnlyReferencedViaReflectionWhichShouldSuppress--", ProducedBy = Tool.NativeAot)]
                        // NonPublicMethods doesn't warn for members emitted into compiler-generated state machine types.
                        static void TestNonPublicMethods ()
                        {
@@ -1975,14 +2013,26 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
                        // Warnings for Reflection access to methods with Requires
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionInMethodWithRequires--")]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionWithClosureInMethodWithRequires--")]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionWithClosureInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionWithClosureInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionInMethodWithRequiresOnlyAccessedViaReflection--")]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionInMethodWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionInMethodWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.NativeAot)]
                        // Trimming tools correctly emit warnings about reflection access to local functions with Requires
                        // or which inherit Requires from the containing method. The analyzer doesn't bind to local functions
                        // so does not warn here.
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionWithRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionWithRequires--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionWithClosureWithRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionWithClosureWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionWithClosureWithRequires--", ProducedBy = Tool.NativeAot)]
                        // BUG: https://github.com/dotnet/runtime/issues/68786
                        // NativeAot doesn't associate Requires on method with the local functions it contains.
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionInMethodWithRequires--", ProducedBy = Tool.Trimmer)]
@@ -1998,12 +2048,24 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
                        // Warnings for Reflection access to methods with Requires
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionInMethodWithRequires--")]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionWithClosureInMethodWithRequires--")]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionWithClosureInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionWithClosureInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionInMethodWithRequiresOnlyAccessedViaReflection--")]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionInMethodWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionInMethodWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.NativeAot)]
                        // NonPublicMethods warns for local functions not emitted into display classes.
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionWithRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionWithRequires--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionWithRequiresOnlyAccessedViaReflection--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionWithClosureWithRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--TestLocalFunctionWithClosureWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLocalFunctionWithClosureWithRequires--", ProducedBy = Tool.NativeAot)]
                        // BUG: https://github.com/dotnet/runtime/issues/68786
                        // NativeAot doesn't associate Requires on method with the local functions it contains.
                        [ExpectedWarning ("IL2026", "--TestLocalFunctionInMethodWithRequires--", ProducedBy = Tool.Trimmer)]
@@ -2027,8 +2089,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                class LambdasReferencedViaReflection
                {
                        [ExpectedWarning ("IL2026", "--TestLambdaWithRequires--")]
-                       [ExpectedWarning ("IL3002", "--TestLambdaWithRequires--", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "--TestLambdaWithRequires--", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "--TestLambdaWithRequires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLambdaWithRequires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        static void TestLambdaWithRequires ()
                        {
                                var lambda =
@@ -2041,8 +2103,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                        }
 
                        [ExpectedWarning ("IL2026", "Lambda")]
-                       [ExpectedWarning ("IL3002", "Lambda", ProducedBy = Tool.Analyzer)]
-                       [ExpectedWarning ("IL3050", "Lambda", ProducedBy = Tool.Analyzer)]
+                       [ExpectedWarning ("IL3002", "Lambda", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "Lambda", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
                        static void TestLambdaWithClosureWithRequires (int p = 0)
                        {
                                var lambda =
@@ -2082,12 +2144,20 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
                        // Warnings for Reflection access to methods with Requires
                        [ExpectedWarning ("IL2026", "--TestLambdaInMethodWithRequires--")]
+                       [ExpectedWarning ("IL3002", "--TestLambdaInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLambdaInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLambdaWithClosureInMethodWithRequires--")]
+                       [ExpectedWarning ("IL3002", "--TestLambdaWithClosureInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLambdaWithClosureInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
                        // Trimming tools correctly emit warnings about reflection access to lambdas with Requires
                        // or which inherit Requires from the containing method. The analyzer doesn't bind to lambdas
                        // so does not warn here.
                        [ExpectedWarning ("IL2026", "--TestLambdaWithRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--TestLambdaWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLambdaWithRequires--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLambdaWithClosureWithRequires--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
+                       [ExpectedWarning ("IL3002", "--TestLambdaWithClosureWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLambdaWithClosureWithRequires--", ProducedBy = Tool.NativeAot)]
                        // BUG: https://github.com/dotnet/runtime/issues/68786
                        // NativeAot doesn't associate Requires on method with the lambdas it contains.
                        [ExpectedWarning ("IL2026", "--TestLambdaInMethodWithRequires--", ProducedBy = Tool.Trimmer)]
@@ -2099,7 +2169,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
 
                        // Warnings for Reflection access to methods with Requires
                        [ExpectedWarning ("IL2026", "--TestLambdaInMethodWithRequires--")]
+                       [ExpectedWarning ("IL3002", "--TestLambdaInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLambdaInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
                        [ExpectedWarning ("IL2026", "--TestLambdaWithClosureInMethodWithRequires--")]
+                       [ExpectedWarning ("IL3002", "--TestLambdaWithClosureInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
+                       [ExpectedWarning ("IL3050", "--TestLambdaWithClosureInMethodWithRequires--", ProducedBy = Tool.NativeAot)]
                        // NonPublicMethods doesn't warn for lambdas emitted into display class types.
                        static void TestNonPublicMethods ()
                        {
index 1c36ec0..06294b2 100644 (file)
@@ -190,6 +190,7 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                                }
                        }
 
+                       // https://github.com/dotnet/runtime/issues/73321
                        [ExpectedWarning ("IL2026", "--CovariantReturnViaLdftn.Derived.GetRequires--")]
                        [ExpectedWarning ("IL3002", "--CovariantReturnViaLdftn.Derived.GetRequires--", ProducedBy = Tool.Analyzer)]
                        [ExpectedWarning ("IL3050", "--CovariantReturnViaLdftn.Derived.GetRequires--", ProducedBy = Tool.Analyzer)]
index 9440665..f4d768a 100644 (file)
@@ -18,7 +18,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                // Base/Derived and Implementation/Interface differs between ILLink and analyzer https://github.com/dotnet/linker/issues/2533
                [ExpectedWarning ("IL2026", "--DynamicallyAccessedTypeWithRequires.MethodWithRequires--")]
                [ExpectedWarning ("IL2026", "TypeWhichOverridesMethod.VirtualMethodRequires()", "--TypeWhichOverridesMethod.VirtualMethodRequires--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "TypeWhichOverridesMethod.VirtualMethodRequires()", "--TypeWhichOverridesMethod.VirtualMethodRequires--", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "TypeWhichOverridesMethod.VirtualMethodRequires()", "--TypeWhichOverridesMethod.VirtualMethodRequires--", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "BaseType.VirtualMethodRequires()", "--BaseType.VirtualMethodRequires--")]
+               [ExpectedWarning ("IL3002", "BaseType.VirtualMethodRequires()", "--BaseType.VirtualMethodRequires--", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "BaseType.VirtualMethodRequires()", "--BaseType.VirtualMethodRequires--", ProducedBy = Tool.NativeAot)]
                public static void Main ()
                {
                        TestDynamicallyAccessedMembersWithRequires (typeof (DynamicallyAccessedTypeWithRequires));
@@ -66,14 +70,13 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                {
                }
 
-               [ExpectedWarning ("IL2026", "--RequiresInDynamicDependency--")]
+               // https://github.com/dotnet/runtime/issues/83080 - Analyzer doesn't recognize DynamicDependency in any way
                [ExpectedWarning ("IL2026", "--RequiresInDynamicDependency--", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
-               [ExpectedWarning ("IL3002", "--RequiresInDynamicDependency--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
-               [ExpectedWarning ("IL3050", "--RequiresInDynamicDependency--", ProducedBy = Tool.Analyzer | Tool.NativeAot)]
+               [ExpectedWarning ("IL3002", "--RequiresInDynamicDependency--", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "--RequiresInDynamicDependency--", ProducedBy = Tool.NativeAot)]
                [DynamicDependency ("RequiresInDynamicDependency")]
                static void TestRequiresInDynamicDependency ()
                {
-                       RequiresInDynamicDependency ();
                }
        }
 }
index 19688cf..7983515 100644 (file)
@@ -33,7 +33,11 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
        class RequiresWithCopyAssembly
        {
                [ExpectedWarning ("IL2026", "--IDerivedInterface.MethodInDerivedInterface--")]
+               [ExpectedWarning ("IL3002", "--IDerivedInterface.MethodInDerivedInterface--", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "--IDerivedInterface.MethodInDerivedInterface--", ProducedBy = Tool.NativeAot)]
                [ExpectedWarning ("IL2026", "--IBaseInterface.MethodInBaseInterface--")]
+               [ExpectedWarning ("IL3002", "--IBaseInterface.MethodInBaseInterface--", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "--IBaseInterface.MethodInBaseInterface--", ProducedBy = Tool.NativeAot)]
                public static void Main ()
                {
                        TestRequiresInMethodFromCopiedAssembly ();
@@ -51,6 +55,8 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
                }
 
                [ExpectedWarning ("IL2026", "--MethodCalledThroughReflection--")]
+               [ExpectedWarning ("IL3002", "--MethodCalledThroughReflection--", ProducedBy = Tool.NativeAot)]
+               [ExpectedWarning ("IL3050", "--MethodCalledThroughReflection--", ProducedBy = Tool.NativeAot)]
                static void TestRequiresThroughReflectionInMethodFromCopiedAssembly ()
                {
                        typeof (RequiresInCopyAssembly)