From: Vitek Karas <10670590+vitek-karas@users.noreply.github.com> Date: Thu, 4 May 2023 07:59:13 +0000 (-0700) Subject: Enable more ILLink tests in NativeAOT (#85651) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~2455 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3232ad36a791b7b8dce81c3358cd6cec4e42c06e;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Enable more ILLink tests in NativeAOT (#85651) Product fixes: * Fix tracking of arrays in NativeAOT * Fix handling of arrays in ILLink Test fixes: * Consider reflection enabled methods as marked (even if they don't have an entrypoint, like interface methods) * Fix where to look for ilasm * Better handling of compiled dependenceis * Ignore some more compiler generated code (which can't be marked as kept) Enables several more data flow tests from linker for AOT as well. Updates some bug links to point to runtime repo. --- diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs index 48c1c0b7cc3..b6a0997701b 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs @@ -626,8 +626,8 @@ namespace ILCompiler { foreach (var node in MarkedNodes) { - if (node is IMethodBodyNode) - yield return ((IMethodBodyNode)node).Method; + if (node is IMethodBodyNode methodBodyNode) + yield return methodBodyNode.Method; } } } @@ -639,9 +639,7 @@ namespace ILCompiler foreach (var node in MarkedNodes) { if (node is ConstructedEETypeNode || node is CanonicalEETypeNode) - { yield return ((IEETypeNode)node).Type; - } } } } @@ -652,10 +650,20 @@ namespace ILCompiler { foreach (var node in MarkedNodes) { - if (node is IEETypeNode) - { - yield return ((IEETypeNode)node).Type; - } + if (node is IEETypeNode typeNode) + yield return typeNode.Type; + } + } + } + + public IEnumerable ReflectedMethods + { + get + { + foreach (var node in MarkedNodes) + { + if (node is ReflectedMethodNode reflectedMethod) + yield return reflectedMethod.Method; } } } 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 b9312b0e109..e489edce4ad 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs @@ -1025,6 +1025,10 @@ namespace ILLink.Shared.TrimAnalysis // All values except for Nullable, including Nullable<> (with no type arguments) return new SystemTypeValue(genericArgumentType); } + else if (genericArgument is ArrayType arrayType) + { + return new SystemTypeValue(arrayType); + } else { return UnknownValue.Instance; diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests/Mono.Linker.Tests.csproj b/src/coreclr/tools/aot/Mono.Linker.Tests/Mono.Linker.Tests.csproj index 72fd7dffe14..dc1dd6f608c 100644 --- a/src/coreclr/tools/aot/Mono.Linker.Tests/Mono.Linker.Tests.csproj +++ b/src/coreclr/tools/aot/Mono.Linker.Tests/Mono.Linker.Tests.csproj @@ -38,6 +38,9 @@ $(ArtifactsDir) + + $(CoreCLRArtifactsPath) + $(ArtifactsBinDir) diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs index b2ef8520914..961e4b6a9c0 100644 --- a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs +++ b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs @@ -8,8 +8,6 @@ using System.Linq; using System.Text; using FluentAssertions; using ILCompiler; -using ILCompiler.DependencyAnalysis; -using Internal.IL.Stubs; using Internal.TypeSystem; using Internal.TypeSystem.Ecma; using Mono.Cecil; @@ -42,7 +40,10 @@ namespace Mono.Linker.Tests.TestCasesRunner // Ignore NativeAOT injected members ".StartupCodeMain(Int32,IntPtr)", - ".MainMethodWrapper()" + ".MainMethodWrapper()", + + // Ignore compiler generated code which can't be reasonably matched to the source method + "", }; public AssemblyChecker ( @@ -130,6 +131,10 @@ namespace Mono.Linker.Tests.TestCasesRunner AddMethod (method); } + foreach (MethodDesc method in testResult.TrimmingResults.ReflectedMethods) { + AddMethod (method); + } + void AddMethod (MethodDesc method) { MethodDesc methodDef = method.GetTypicalMethodDefinition (); diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/ILCompilerDriver.cs b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/ILCompilerDriver.cs index 2864f4c2c88..d5fa880badf 100644 --- a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/ILCompilerDriver.cs +++ b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/ILCompilerDriver.cs @@ -64,6 +64,16 @@ namespace Mono.Linker.Tests.TestCasesRunner compilationRoots.Add (new MainMethodRootProvider (entrypointModule, CreateInitializerList (typeSystemContext, options), generateLibraryAndModuleInitializers: true)); + foreach (var rootedAssembly in options.AdditionalRootAssemblies) { + EcmaModule module = typeSystemContext.GetModuleForSimpleName (rootedAssembly); + + // We only root the module type. The rest will fall out because we treat rootedAssemblies + // same as conditionally rooted ones and here we're fulfilling the condition ("something is used"). + compilationRoots.Add ( + new GenericRootProvider (module, + (ModuleDesc module, IRootingServiceProvider rooter) => rooter.AddReflectionRoot (module.GetGlobalModuleType (), "Command line root"))); + } + ILProvider ilProvider = new NativeAotILProvider (); Logger logger = new Logger ( diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/ILInputCompiler.cs b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/ILInputCompiler.cs index bffa9822c35..22b7a621acc 100644 --- a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/ILInputCompiler.cs +++ b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/ILInputCompiler.cs @@ -61,10 +61,9 @@ namespace Mono.Linker.Tests.TestCasesRunner #if NETCOREAPP var extension = RuntimeInformation.IsOSPlatform (OSPlatform.Windows) ? ".exe" : ""; - // working directory is artifacts/bin/Mono.Linker.Tests// - var toolsDir = Path.Combine (Directory.GetCurrentDirectory (), "..", "..", "..", "..", "tools"); + var toolsDir = (string) AppContext.GetData ("Mono.Linker.Tests.ILToolsDir")!; - var ilasmPath = Path.GetFullPath (Path.Combine (toolsDir, "ilasm", $"ilasm{extension}")).ToNPath (); + var ilasmPath = Path.GetFullPath (Path.Combine (toolsDir, $"ilasm{extension}")).ToNPath (); if (ilasmPath.FileExists ()) return ilasmPath; diff --git a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs index 50442019768..5e9a63db86c 100644 --- a/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs +++ b/src/coreclr/tools/aot/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs @@ -129,11 +129,9 @@ namespace Mono.Linker.Tests.TestCasesRunner foreach (var inputReference in sandbox.InputDirectory.Files ()) { var ext = inputReference.ExtensionWithDot; if (ext == ".dll" || ext == ".exe") { - if (caseDefinedOptions.AssembliesAction.Contains (("link", inputReference.FileNameWithoutExtension))) { - builder.AddLinkAssembly (inputReference); - } else { - builder.AddReference (inputReference); - } + // It's important to add all assemblies as "link" assemblies since the default configuration + // is to run the compiler in multi-file mode which will not process anything which is just in the reference set. + builder.AddLinkAssembly (inputReference); } } var coreAction = caseDefinedOptions.TrimMode ?? "skip"; diff --git a/src/tools/illink/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs b/src/tools/illink/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs index 0b357b56330..28780d11239 100644 --- a/src/tools/illink/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs +++ b/src/tools/illink/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs @@ -303,12 +303,14 @@ namespace Mono.Linker.Dataflow if (staticType is null) { // We don't know anything about the type GetType was called on. Track this as a usual result of a method call without any annotations AddReturnValue (context.Annotations.FlowAnnotations.GetMethodReturnValue (calledMethodDefinition)); - } else if (staticType.IsSealed || staticType.IsTypeOf ("System", "Delegate")) { + } else if (staticType.IsSealed || staticType.IsTypeOf ("System", "Delegate") || staticType.IsTypeOf ("System", "Array")) { // We can treat this one the same as if it was a typeof() expression // We can allow Object.GetType to be modeled as System.Delegate because we keep all methods // on delegates anyway so reflection on something this approximation would miss is actually safe. + // We can also treat all arrays as "sealed" since it's not legal to derive from Array type (even though it is not sealed itself) + // We ignore the fact that the type can be annotated (see below for handling of annotated types) // This means the annotations (if any) won't be applied - instead we rely on the exact knowledge // of the type. So for example even if the type is annotated with PublicMethods diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs index bd89abc447d..b7c71da382b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs @@ -179,7 +179,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } [Kept] - // https://github.com/dotnet/linker/issues/2874 + // https://github.com/dotnet/runtime/issues/85464 [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer | Tool.NativeAot)] [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer | Tool.NativeAot)] public static void Test () diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeInPreservedAssembly.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeInPreservedAssembly.cs index 722720553ad..9e382e40a38 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeInPreservedAssembly.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/CompilerGeneratedCodeInPreservedAssembly.cs @@ -10,8 +10,7 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] - // This test tries to hit a case where the entire assemly is preserved (via descriptor, NOT action) + // This test tries to hit a case where the entire assembly is preserved (via descriptor, NOT action) // meaning we will go and mark all types and members in it. // At the same time there's a compiler generated method (local function) which is called from // a branch which will be removed due to constant propagation. @@ -44,7 +43,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // Analyzer doesn't implement constant propagation and branch removal, so it reaches this code - [ExpectedWarning ("IL2026", ProducedBy = Tool.Analyzer)] + // NativeAOT behavioral difference: + // https://github.com/dotnet/runtime/issues/85161 + [ExpectedWarning ("IL2026", ProducedBy = Tool.Analyzer | Tool.NativeAot)] void LocalWithWarning () { // No warning @@ -64,7 +65,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // Analyzer doesn't implement constant propagation and branch removal, so it reaches this code - [ExpectedWarning ("IL2026", ProducedBy = Tool.Analyzer)] + // NativeAOT behavioral difference: + // https://github.com/dotnet/runtime/issues/85161 + [ExpectedWarning ("IL2026", ProducedBy = Tool.Analyzer | Tool.NativeAot)] void LocalWithWarning () { Requires (); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs index 594a1926eec..343edfcc63c 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ComplexTypeHandling.cs @@ -11,8 +11,9 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] - [KeptAttributeAttribute (typeof (IgnoreTestCaseAttribute), By = Tool.Trimmer)] + [ExpectedNoWarnings] + [UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Applying DAM PublicMethods on an array will mark Array.CreateInstance which has RDC on it")] + [KeptAttributeAttribute(typeof(UnconditionalSuppressMessageAttribute))] public class ComplexTypeHandling { public static void Main () @@ -93,7 +94,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow _ = new RequirePublicMethodsGeneric (); } - [Kept] + [Kept (By = Tool.Trimmer)] // NativeAOT doesn't preserve array element types just due to the usage of the array type sealed class ArrayGetTypeFromMethodParamElement { // This method should not be marked, instead Array.* should be marked @@ -112,7 +113,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow TestArrayGetTypeFromMethodParamHelper (null); } - [Kept] + [Kept (By = Tool.Trimmer)] // NativeAOT doesn't preserve array element types just due to the usage of the array type sealed class ArrayGetTypeFromFieldElement { // This method should not be marked, instead Array.* should be marked @@ -141,11 +142,11 @@ namespace Mono.Linker.Tests.Cases.DataFlow RequirePublicMethods (Type.GetType ("Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayTypeGetTypeElement[]")); } - // Technically there's no reason to mark this type since it's only used as an array element type and CreateInstance - // doesn't work on arrays, but the currently implementation will preserve it anyway due to how it processes + // Trimmer: Technically there's no reason to mark this type since it's only used as an array element type and CreateInstance + // doesn't work on arrays, but the current implementation will preserve it anyway due to how it processes // string -> Type resolution. This will only impact code which would have failed at runtime, so very unlikely to // actually occur in real apps (and even if it does happen, it just increases size, doesn't break behavior). - [Kept] + [Kept (By = Tool.Trimmer)] // NativeAOT doesn't preserve array element types just due to the usage of the array type class ArrayCreateInstanceByNameElement { public ArrayCreateInstanceByNameElement () @@ -154,12 +155,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow } [Kept] + [ExpectedWarning ("IL2032", ProducedBy = Tool.NativeAot)] // https://github.com/dotnet/runtime/issues/82447 static void TestArrayCreateInstanceByName () { Activator.CreateInstance ("test", "Mono.Linker.Tests.Cases.DataFlow.ComplexTypeHandling+ArrayCreateInstanceByNameElement[]"); } - [Kept] + [Kept (By = Tool.Trimmer)] // NativeAOT doesn't preserve array element types just due to the usage of the array type class ArrayInAttributeParamElement { // This method should not be marked, instead Array.* should be marked @@ -169,10 +171,17 @@ namespace Mono.Linker.Tests.Cases.DataFlow [Kept] [KeptAttributeAttribute (typeof (RequiresPublicMethodAttribute))] [RequiresPublicMethod (typeof (ArrayInAttributeParamElement[]))] - static void TestArrayInAttributeParameter () + static void TestArrayInAttributeParameterImpl () { } + [Kept] + static void TestArrayInAttributeParameter() + { + // Have to access the method through reflection, otherwise NativeAOT will remove all attributes on it + // since they're not accessible. + typeof (ComplexTypeHandling).GetMethod (nameof (TestArrayInAttributeParameterImpl), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).Invoke (null, new object[] { }); + } [Kept] private static void RequirePublicMethods ( diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ConstructedTypesDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ConstructedTypesDataFlow.cs index 22584259fcd..3bc10b9aa5f 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ConstructedTypesDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ConstructedTypesDataFlow.cs @@ -12,7 +12,6 @@ using Mono.Linker.Tests.Cases.Expectations.Helpers; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] [ExpectedNoWarnings] [SkipKeptItemsValidation] class ConstructedTypesDataFlow diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MakeGenericDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MakeGenericDataFlow.cs index b8ef7d98ea7..579a775301f 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MakeGenericDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MakeGenericDataFlow.cs @@ -7,7 +7,6 @@ using BindingFlags = System.Reflection.BindingFlags; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] [SkipKeptItemsValidation] [ExpectedNoWarnings] [UnconditionalSuppressMessage ("AOT", "IL3050", Justification = "These tests are not targetted at AOT scenarios")] @@ -85,7 +84,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // https://github.com/dotnet/linker/issues/2755 - [ExpectedWarning ("IL2055", nameof (Type.MakeGenericType), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2055", nameof (Type.MakeGenericType), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestWithUnknownTypeArray (Type[] types) { typeof (GenericWithPublicFieldsArgument<>).MakeGenericType (types); @@ -100,7 +99,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // https://github.com/dotnet/linker/issues/2755 - [ExpectedWarning ("IL2055", nameof (Type.MakeGenericType), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2055", nameof (Type.MakeGenericType), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestWithArrayUnknownLengthSet (int arrayLen) { Type[] types = new Type[arrayLen]; @@ -424,14 +423,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // https://github.com/dotnet/linker/issues/2755 - [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestUnknownMethod (MethodInfo mi) { mi.MakeGenericMethod (typeof (TestType)); } // https://github.com/dotnet/linker/issues/2755 - [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestUnknownMethodButNoTypeArguments (MethodInfo mi) { // Technically trimming could figure this out, but it's not worth the complexity - such call will always fail at runtime. @@ -542,7 +541,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // https://github.com/dotnet/linker/issues/2755 - [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestWithUnknownTypeArray (Type[] types) { typeof (MakeGenericMethod).GetMethod (nameof (GenericWithRequirements), BindingFlags.Static) @@ -559,7 +558,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // https://github.com/dotnet/linker/issues/2158 - analyzer doesn't work the same as ILLink, it simply doesn't handle refs - [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestWithArrayUnknownIndexSetByRef (int indexToSet) { Type[] types = new Type[1]; @@ -571,7 +570,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // https://github.com/dotnet/linker/issues/2755 - [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2060", nameof (MethodInfo.MakeGenericMethod), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestWithArrayUnknownLengthSet (int arrayLen) { Type[] types = new Type[arrayLen]; diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs index 9d3bcbf5119..7bcdeb59729 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypes.cs @@ -11,69 +11,15 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] - [KeptAttributeAttribute (typeof (IgnoreTestCaseAttribute), By = Tool.Trimmer)] [SetupCompileArgument ("/optimize+")] [ExpectedNoWarnings] public class MemberTypes { - // Some of the types below declare delegates and will mark all members on them, this includes the Delegate .ctor(object, string) which has RUC and other members - [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2026", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate")] - [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate")] - [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate")] - [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate")] - [ExpectedWarning ("IL2026", nameof (MulticastDelegate) + ".MulticastDelegate")] - // Some of the types below declare delegates and will mark all members on them, this includes the Delegate .ctor(Type, string) which has DAM annotations and other members - [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2111", nameof (Delegate) + ".Delegate")] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (Delegate.CreateDelegate))] - [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate")] - [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate")] - [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate")] - [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate")] - [ExpectedWarning ("IL2111", nameof (MulticastDelegate) + ".MulticastDelegate")] - [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2111", nameof (Delegate) + ".BindToMethodName", ProducedBy = Tool.Trimmer)] + // This is an easy way to suppress all trim related warnings in the Main method + // This test is about marking, not diagnostics and this Main will produce several warnings due to it accssing + // some problematic APIs (Delegate.Create for example) via reflection. + [RequiresUnreferencedCode("test")] + [KeptAttributeAttribute(typeof(RequiresUnreferencedCodeAttribute))] public static void Main () { RequirePublicParameterlessConstructor (typeof (PublicParameterlessConstructorType)); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs index 4ac5f0edfe2..716662e19e8 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MemberTypesAllOnCopyAssembly.cs @@ -13,8 +13,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] - [KeptAttributeAttribute (typeof (IgnoreTestCaseAttribute), By = Tool.Trimmer)] [ExpectedNoWarnings] [SetupCompileBefore ("base.dll", new[] { "Dependencies/MemberTypesAllBaseTypeAssembly.cs" })] @@ -67,7 +65,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow [KeptTypeInAssembly ("base.dll", "Mono.Linker.Tests.Cases.DataFlow.Dependencies.MemberTypesAllBaseType/PrivateNestedType")] [KeptMemberInAssembly ("base.dll", "Mono.Linker.Tests.Cases.DataFlow.Dependencies.MemberTypesAllBaseType/PrivateNestedType", new string[] { "PrivateMethod()" })] - [KeptMember (".ctor()")] + // https://github.com/dotnet/runtime/issues/78752 + [KeptMember (".ctor()", By = Tool.Trimmer)] public class MemberTypesAllOnCopyAssembly { public static void Main () diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs index 207152b8203..b4ca654728b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs @@ -11,7 +11,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] [SkipKeptItemsValidation] [ExpectedNoWarnings] class MethodByRefParameterDataFlow @@ -202,11 +201,11 @@ namespace Mono.Linker.Tests.Cases.DataFlow [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] static ref Type GetTypeRefWithMethodsAndFields () { throw null; } - [ExpectedWarning ("IL2067", "t", "InnerMethodWithDam")] - [ExpectedWarning ("IL2067", "tWithMethodsAndFields", "InnerMethodWithDam")] + [ExpectedWarning ("IL2067", "'t'", "InnerMethodWithDam")] + [ExpectedWarning ("IL2067", "'tWithMethodsAndFields'", "InnerMethodWithDam")] [ExpectedWarning ("IL2072", nameof (GetTypeRefWithoutAnnotations), "InnerMethodWithDam")] [ExpectedWarning ("IL2068", nameof (GetTypeRefWithMethodsAndFields), "InnerMethodWithDam")] - static void MethodWithLocaMethodWithDam (Type t, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type tWithMethods, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] Type tWithMethodsAndFields) + static void MethodWithLocalMethodWithDam (Type t, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type tWithMethods, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] Type tWithMethodsAndFields) { // 2067 InnerMethodWithDam (ref t); @@ -233,7 +232,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow public static void Test () { - MethodWithLocaMethodWithDam (null, null, null); + MethodWithLocalMethodWithDam (null, null, null); } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs index d8181182626..348df96e99b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs @@ -10,8 +10,6 @@ using DAMT = System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] - [KeptAttributeAttribute (typeof (IgnoreTestCaseAttribute), By = Tool.Trimmer)] [ExpectedNoWarnings] [KeptPrivateImplementationDetails ("ThrowSwitchExpressionException")] [KeptAttributeAttribute (typeof (UnconditionalSuppressMessageAttribute))] @@ -301,7 +299,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow [Kept] // https://github.com/dotnet/linker/issues/2755 - [ExpectedWarning ("IL2075", "GetFields", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2075", "GetFields", ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void MakeGenericTypeWithKnowAndUnknownArray (Type[] unknownTypes = null, int p = 0) { Type[] types = p switch { 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 1d8509978f1..1c3713e274b 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 @@ -9,7 +9,6 @@ using Mono.Linker.Tests.Cases.Expectations.Helpers; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] // Note: this test's goal is to validate that the product correctly reports unrecognized patterns // - so the main validation is done by the ExpectedWarning attributes. [SkipKeptItemsValidation] @@ -273,7 +272,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273 [ExpectedWarning ("IL2042", "Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow.TestAutomaticPropagationType.PropertyWithDifferentBackingFields", - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] [ExpectedWarning ("IL2078", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithDifferentBackingFields) + ".get", "Type", @@ -282,7 +281,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow Type PropertyWithDifferentBackingFields { [ExpectedWarning ("IL2078", nameof (TestAutomaticPropagationType) + "." + nameof (PropertyWithDifferentBackingFields) + ".get", - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] get { return PropertyWithDifferentBackingFields_GetterField; } @@ -300,7 +299,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273 [ExpectedWarning ("IL2056", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes_Field", - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] [CompilerGenerated] Type PropertyWithExistingAttributes_Field; @@ -311,13 +310,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow Type PropertyWithExistingAttributes { // On property/accessor mismatch, ILLink warns on accessor and analyzer warns on property https://github.com/dotnet/linker/issues/2654 [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.get", - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] get { return PropertyWithExistingAttributes_Field; } // On property/accessor mismatch, ILLink warns on accessor and analyzer warns on property https://github.com/dotnet/linker/issues/2654 [ExpectedWarning ("IL2043", "PropertyWithExistingAttributes", "PropertyWithExistingAttributes.set", - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] [param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] set { PropertyWithExistingAttributes_Field = value; } } @@ -338,7 +337,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow // Analyzer doesn't try to detect backing fields of properties: https://github.com/dotnet/linker/issues/2273 [ExpectedWarning ("IL2056", "PropertyWithConflictingAttributes", "PropertyWithConflictingAttributes_Field", - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)] [CompilerGenerated] Type PropertyWithConflictingAttributes_Field; @@ -349,13 +348,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow Type PropertyWithConflictingAttributes { // On property/accessor mismatch, ILLink warns on accessor and analyzer warns on property https://github.com/dotnet/linker/issues/2654 [ExpectedWarning ("IL2043", "PropertyWithConflictingAttributes", "PropertyWithConflictingAttributes.get", - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)] get { return PropertyWithConflictingAttributes_Field; } // On property/accessor mismatch, ILLink warns on accessor and analyzer warns on property https://github.com/dotnet/linker/issues/2654 [ExpectedWarning ("IL2043", "PropertyWithConflictingAttributes", "PropertyWithConflictingAttributes.set", - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] [param: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.NonPublicConstructors)] set { PropertyWithConflictingAttributes_Field = value; } } @@ -399,7 +398,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // Trimmer and analyzer handle formatting of indexers differently. - [ExpectedWarning ("IL2067", nameof (PropertyWithIndexer) + ".Item.set", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2067", nameof (PropertyWithIndexer) + ".Item.set", ProducedBy = Tool.Trimmer | Tool.NativeAot)] [ExpectedWarning ("IL2067", nameof (PropertyWithIndexer) + ".this[Int32].set", ProducedBy = Tool.Analyzer)] [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors) + "(Type)")] [LogDoesNotContain ("'Value passed to parameter 'index' of method 'Mono.Linker.Tests.Cases.DataFlow.PropertyDataFlow.TestAutomaticPropagationType.PropertyWithIndexer.Item.set'")] @@ -418,7 +417,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] public Type this[int index] { // Trimmer and analyzer handle formatting of indexers differently. - [ExpectedWarning ("IL2063", nameof (PropertyWithIndexer) + ".Item.get", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2063", nameof (PropertyWithIndexer) + ".Item.get", ProducedBy = Tool.Trimmer | Tool.NativeAot)] [ExpectedWarning ("IL2063", nameof (PropertyWithIndexer) + ".this[Int32].get", ProducedBy = Tool.Analyzer)] get => Property_Field[index]; set => Property_Field[index] = value; @@ -483,7 +482,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow // Analyzer doesn't warn about compiler-generated backing field of property: https://github.com/dotnet/linker/issues/2731 [ExpectedWarning ("IL2074", nameof (WriteToGetOnlyProperty), nameof (GetUnknownType), - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] public WriteToGetOnlyProperty () { GetOnlyProperty = GetUnknownType (); @@ -551,9 +550,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow // Analyzer doesn't warn about compiler-generated backing field of property: https://github.com/dotnet/linker/issues/2731 [ExpectedWarning ("IL2074", nameof (WriteCapturedGetOnlyProperty), nameof (GetUnknownType), - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] [ExpectedWarning ("IL2074", nameof (WriteCapturedGetOnlyProperty), nameof (GetTypeWithPublicConstructors), - ProducedBy = Tool.Trimmer)] + ProducedBy = Tool.Trimmer | Tool.NativeAot)] public WriteCapturedGetOnlyProperty () { GetOnlyProperty = GetUnknownType () ?? GetTypeWithPublicConstructors (); @@ -666,14 +665,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow } [ExpectedWarning ("IL2072", "this[Index].get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2072", "Item.get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2072", "Item.get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestRead (ExplicitIndexerAccess instance = null) { instance[new Index (1)].RequiresAll (); } [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "this[Index].set", ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "Item.set", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "Item.set", ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestWrite (ExplicitIndexerAccess instance = null) { instance[^1] = GetTypeWithPublicConstructors (); @@ -697,21 +696,21 @@ namespace Mono.Linker.Tests.Cases.DataFlow int Length => throw new NotImplementedException (); [ExpectedWarning ("IL2072", "this[Int32].get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2072", "Item.get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2072", "Item.get", nameof (DataFlowTypeExtensions.RequiresAll), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestRead (ImplicitIndexerAccess instance = null) { instance[new Index (1)].RequiresAll (); } [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "this[Int32].set", ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "Item.set", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2072", nameof (GetTypeWithPublicConstructors), "Item.set", ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestWrite (ImplicitIndexerAccess instance = null) { instance[^1] = GetTypeWithPublicConstructors (); } [ExpectedWarning ("IL2072", nameof (GetUnknownType), "this[Int32].set", ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2072", nameof (GetUnknownType), "Item.set", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2072", nameof (GetUnknownType), "Item.set", ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TestNullCoalescingAssignment (ImplicitIndexerAccess instance = null) { instance[new Index (1)] ??= GetUnknownType (); @@ -736,7 +735,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } [ExpectedWarning ("IL2067", "this[Type].get", nameof (ParamDoesNotMeetRequirements), ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2067", "Item.get", nameof (ParamDoesNotMeetRequirements), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2067", "Item.get", nameof (ParamDoesNotMeetRequirements), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void ParamDoesNotMeetRequirements (Type t) { var x = new IndexWithTypeWithDam (); @@ -750,7 +749,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } [ExpectedWarning ("IL2087", "this[Type].get", nameof (TypeParamDoesNotMeetRequirements), ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2087", "Item.get", nameof (TypeParamDoesNotMeetRequirements), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2087", "Item.get", nameof (TypeParamDoesNotMeetRequirements), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TypeParamDoesNotMeetRequirements () { var x = new IndexWithTypeWithDam (); @@ -791,7 +790,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow static Type fieldWithMethods; [ExpectedWarning ("IL2067", "this[Type].get", nameof (ParamDoesNotMeetRequirements), ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2067", "Item.get", nameof (ParamDoesNotMeetRequirements), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2067", "Item.get", nameof (ParamDoesNotMeetRequirements), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void ParamDoesNotMeetRequirements (Type t) { var x = new IndexWithTypeWithDam (); @@ -805,7 +804,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } [ExpectedWarning ("IL2087", "this[Type].get", nameof (TypeParamDoesNotMeetRequirements), ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2087", "Item.get", nameof (TypeParamDoesNotMeetRequirements), ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2087", "Item.get", nameof (TypeParamDoesNotMeetRequirements), ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void TypeParamDoesNotMeetRequirements () { var x = new IndexWithTypeWithDam (); @@ -828,7 +827,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } [ExpectedWarning ("IL2067", "this[Type].set", nameof (t), "idx", ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2067", "Item.set", nameof (t), "idx", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2067", "Item.set", nameof (t), "idx", ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void ValueMeetsRequirementsIndexDoesNot (Type t) { var x = new IndexWithTypeWithDam (); @@ -836,7 +835,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow } [ExpectedWarning ("IL2067", "this[Type].set", nameof (tUnannotated), "value", ProducedBy = Tool.Analyzer)] - [ExpectedWarning ("IL2067", "Item.set", nameof (tUnannotated), "value", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2067", "Item.set", nameof (tUnannotated), "value", ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void ValueDoesNotMeetRequirementsIndexDoes ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] Type t, Type tUnannotated) { var x = new IndexWithTypeWithDam (); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RefFieldDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RefFieldDataFlow.cs index 9db1b0e571b..fdedee546ba 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RefFieldDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RefFieldDataFlow.cs @@ -11,17 +11,16 @@ using DAMT = System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] [SkipKeptItemsValidation] [ExpectedNoWarnings] class RefFieldDataFlow { [Kept] - // Bug for the IL2069's here: https://github.com/dotnet/linker/issues/2874 - [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer)] + // Bug for the IL2069's here: https://github.com/dotnet/runtime/issues/85464 + [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2069", ProducedBy = Tool.Trimmer | Tool.NativeAot)] public static void Main () { RefFieldWithMethods withMethods = new (ref fieldWithMethods); @@ -100,11 +99,11 @@ namespace Mono.Linker.Tests.Cases.DataFlow tmf = typeof (TF); // This is a hole that doesn't warn but assigns a misannotated value to target.T } - [ExpectedWarning ("IL2089", "RefFieldWithMethods", "T", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2089", "RefFieldWithFields", "T", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2089", "RefFieldWithMethodsAndFields", "T", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2089", "RefFieldWithMethodsAndFields", "T", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2089", "RefFieldWithFields", "T", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2089", "RefFieldWithMethods", "T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2089", "RefFieldWithFields", "T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2089", "RefFieldWithMethodsAndFields", "T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2089", "RefFieldWithMethodsAndFields", "T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2089", "RefFieldWithFields", "T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] static void AssignRefLocals< T, [DAM (DAMT.PublicMethods)] TM, @@ -178,13 +177,13 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2069", "RefFieldWithMethods.T", "paramWithFields")] [ExpectedWarning ("IL2077", "paramWithMethodsAndFields", "RefFieldWithMethods.T")] // ILLink doesn't recognize ldind.ref - // https://github.com/dotnet/linker/issues/2943 + // https://github.com/dotnet/runtime/issues/85465 // IL2064's are bugs - shouldn't be unknown values - [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer)] - [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer)] + [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer | Tool.NativeAot)] + [ExpectedWarning ("IL2064", ProducedBy = Tool.Trimmer | Tool.NativeAot)] [ExpectedWarning ("IL2069", "RefFieldWithMethods.T", "param", ProducedBy = Tool.Analyzer)] [ExpectedWarning ("IL2069", "RefFieldWithMethods.T", "paramWithFields", ProducedBy = Tool.Analyzer)] static void AssignRefParameters< @@ -240,12 +239,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2079", "RefFieldWithMethods.T", "RefFieldUnannotated.T", ProducedBy = Tool.Analyzer)] [ExpectedWarning ("IL2079", "RefFieldWithMethods.T", "RefFieldWithFields.T", ProducedBy = Tool.Analyzer)] // IL2064's are bugs - shouldn't be unknown values - // https://github.com/dotnet/linker/issues/2943 - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = unannotated.T; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = withMethods.T; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = withFields.T; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = withMethodsAndFields.T; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = withMethodsAndFields.T; + // https://github.com/dotnet/runtime/issues/85465 + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = unannotated.T; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = withMethods.T; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = withFields.T; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = withMethodsAndFields.T; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = withMethodsAndFields.T; static void AssignRefFields ( RefFieldWithMethods target, RefFieldUnannotated unannotated, @@ -272,11 +271,11 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2074", "RefFieldWithMethods.T", "GetRefUnannotated", ProducedBy = Tool.Analyzer)] [ExpectedWarning ("IL2074", "RefFieldWithMethods.T", "GetRefWithFields", ProducedBy = Tool.Analyzer)] // IL2064's are bugs - shouldn't be unknown values - // https://github.com/dotnet/linker/issues/2943 - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = t; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = t; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = t; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = t; + // https://github.com/dotnet/runtime/issues/85465 + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = t; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = t; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = t; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = t; static void AssignRefReturns< T, [DAM (DAMT.PublicMethods)] TM, @@ -362,16 +361,16 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedWarning ("IL2074", "RefFieldWithMethods.T", "RefPropWithFields.T")] // ref Type t = ref x.T; target.T = t; // IL2064's are bugs - shouldn't be unknown values - // https://github.com/dotnet/linker/issues/2943 - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = unannotated.T; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = withMethods.T; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = withFields.T; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = withMethodsAndFieldswithMtho.T; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = withMethods.T; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = t; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = t; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = t; - [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer)] // target.T = t; + // https://github.com/dotnet/runtime/issues/85465 + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = unannotated.T; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = withMethods.T; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = withFields.T; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = withMethodsAndFieldswithMtho.T; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = withMethods.T; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = t; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = t; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = t; + [ExpectedWarning ("IL2064", "RefFieldWithMethods.T", ProducedBy = Tool.Trimmer | Tool.NativeAot)] // target.T = t; static void AssignRefProperties (RefFieldWithMethods target, RefPropUnannotated unannotated = null, RefPropWithMethods withMethods = null, diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/StaticInterfaceMethodDataflow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/StaticInterfaceMethodDataflow.cs index 5aa1aece4f3..2f922940a3d 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/StaticInterfaceMethodDataflow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/StaticInterfaceMethodDataflow.cs @@ -9,8 +9,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] - [KeptAttributeAttribute (typeof (IgnoreTestCaseAttribute), By = Tool.Trimmer)] + [ExpectedNoWarnings] public class StaticInterfaceMethodDataflow { [Kept] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/TypeInfoIntrinsics.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/TypeInfoIntrinsics.cs index 21a848df98b..6213816a58a 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/TypeInfoIntrinsics.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/TypeInfoIntrinsics.cs @@ -12,7 +12,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.DataFlow { - [IgnoreTestCase ("Ignore in NativeAOT, see https://github.com/dotnet/runtime/issues/82447", IgnoredBy = Tool.NativeAot)] // Note: this test's goal is to validate that the product correctly reports unrecognized patterns // - so the main validation is done by the ExpectedWarning attributes. [SkipKeptItemsValidation] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyMethod.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyMethod.cs index 75db7637339..da049f3ab49 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyMethod.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DynamicDependencies/DynamicDependencyMethod.cs @@ -203,7 +203,7 @@ namespace Mono.Linker.Tests.Cases.DynamicDependencies [KeptMember (".ctor()")] private abstract class AbstractMethods { - [Kept (By = Tool.Trimmer)] // NativeAOT test infra doesn't check reflection-only methods (without entry point) yet + [Kept] [DynamicDependency (nameof (TargetMethod))] public abstract void SourceAbstractViaReflection (); diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXmlNetCore.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXmlNetCore.cs index bf6f717a051..9b9e7130e41 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXmlNetCore.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsUsingTargetViaXmlNetCore.cs @@ -7,6 +7,9 @@ using Mono.Linker.Tests.Cases.Warnings.Dependencies; namespace Mono.Linker.Tests.Cases.Warnings.WarningSuppression { + // https://github.com/dotnet/runtime/issues/82447 + [IgnoreTestCase ("NativeAOT doesn't support suppressing warnings via XML", IgnoredBy = Tool.NativeAot)] + [KeptAttributeAttribute(typeof(IgnoreTestCaseAttribute))] [TestCaseRequirements (TestRunCharacteristics.TargetingNetCore, "This test is specific to .NET Core")] // For netcoreapp we don't have to specify the assembly for the attribute, since the attribute comes from corelib // and will be found always.