diff options
author | Sven Boemer <sbomer@gmail.com> | 2022-08-26 01:46:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-26 01:46:39 +0300 |
commit | 1a134989d42c995a9bbbc909084141ccfa754acd (patch) | |
tree | 692965255ad27b0662c3e22decf95e38371c6a60 | |
parent | ce187dafefb9309e90546d5694de186de683488d (diff) |
Suppress warnings in 6.0 framework (#3000)
This includes a sidecar XML file which will suppress new warnings in
the 6.0 framework.
Note that a few of the new warnings for compiler-generated code are
suppressed in 7.0 with attributes on local functions. In the XML I had
to suppress them with an attribute on the user method (since the
signature format doesn't support compiler-generated code).
Also note that this approach only includes suppressions for the core
framework, not OOB assemblies. OOB assemblies or third-party nuget
packages will require a slightly different approach to avoid warnings
about unresolved members referenced in XML, in apps where those
assemblies aren't used. There are no warnings that we need to suppress
in OOB assemblies - only new warnings in already trim-incompatible
code.
This also includes a fix for a varargs method issue I found while
running on the 6.0 framework.
-rw-r--r-- | src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs | 2 | ||||
-rw-r--r-- | src/ILLink.Tasks/ILLink.Tasks.csproj | 3 | ||||
-rw-r--r-- | src/ILLink.Tasks/build/6.0_suppressions.xml | 156 | ||||
-rw-r--r-- | src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets | 9 | ||||
-rw-r--r-- | src/linker/Linker.Dataflow/MethodBodyScanner.cs | 2 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs | 6 |
6 files changed, 176 insertions, 2 deletions
diff --git a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs index b8f360782..dd4334808 100644 --- a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs +++ b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs @@ -1145,7 +1145,7 @@ namespace ILLink.Shared.TrimAnalysis _requireDynamicallyAccessedMembersAction.Invoke (instanceValue, _annotations.GetMethodThisParameterValue (calledMethod)); } for (int argumentIndex = 0; argumentIndex < argumentValues.Count; argumentIndex++) { - if (calledMethod.ParameterReferenceKind (argumentIndex) == ReferenceKind.Out) + if (argumentIndex >= calledMethod.GetParametersCount () || calledMethod.ParameterReferenceKind (argumentIndex) == ReferenceKind.Out) continue; _requireDynamicallyAccessedMembersAction.Invoke (argumentValues[argumentIndex], _annotations.GetMethodParameterValue (calledMethod, argumentIndex)); } diff --git a/src/ILLink.Tasks/ILLink.Tasks.csproj b/src/ILLink.Tasks/ILLink.Tasks.csproj index 6bf4836d7..bce6899a8 100644 --- a/src/ILLink.Tasks/ILLink.Tasks.csproj +++ b/src/ILLink.Tasks/ILLink.Tasks.csproj @@ -44,6 +44,9 @@ <Content Include="build/Microsoft.NET.ILLink.targets" PackagePath="build/"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> + <Content Include="build/6.0_suppressions.xml" PackagePath="build/"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> </ItemGroup> <ItemGroup> diff --git a/src/ILLink.Tasks/build/6.0_suppressions.xml b/src/ILLink.Tasks/build/6.0_suppressions.xml new file mode 100644 index 000000000..748304129 --- /dev/null +++ b/src/ILLink.Tasks/build/6.0_suppressions.xml @@ -0,0 +1,156 @@ +<?xml version="1.0" encoding="utf-8"?> +<linker> + <assembly fullname="System.Private.CoreLib"> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2070</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Reflection.CustomAttribute.AddCustomAttributes(System.RuntimeType.ListBuilder{System.Object}@,System.Reflection.RuntimeModule,System.Int32,System.RuntimeType,System.Boolean,System.RuntimeType.ListBuilder{System.Object})</property> + <property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property> + </attribute> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2063</argument> + <property name="Scope">member</property> + <property name="Target">M:System.RuntimeType.GetInterface(System.String,System.Boolean)</property> + <property name="Justification">Suppressed in 7.0 for dataflow improvements: https://github.com/dotnet/runtime/commit/2e353d18b81732133aadbee888a801fd9f935fbf</property> + </attribute> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2067</argument> + <property name="Scope">member</property> + <property name="Target">M:System.RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter(System.RuntimeType,System.RuntimeType,System.RuntimeType)</property> + <property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property> + </attribute> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2067</argument> + <property name="Scope">member</property> + <property name="Target">M:System.RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter(System.RuntimeType,System.RuntimeType)</property> + <property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property> + </attribute> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2068</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Reflection.Emit.TypeBuilder.CreateTypeNoLock</property> + <property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property> + </attribute> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2069</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Reflection.Emit.TypeBuilder.CreateTypeNoLock</property> + <property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property> + </attribute> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2119</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Diagnostics.Tracing.EventSource.WriteEventString(System.String)</property> + <property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property> + </attribute> + </assembly> + + <assembly fullname="System.ComponentModel.Annotations"> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2068</argument> + <property name="Scope">member</property> + <property name="Target">M:System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptor.TypeDescriptorCache.GetAssociatedMetadataType(System.Type)</property> + <property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property> + </attribute> + </assembly> + + <assembly fullname="System.Data.Common"> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2060</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Data.DataRowExtensions.UnboxT`1.Create()</property> + <property name="Justification">Suppressed in 7.0 for new constraint warning: https://github.com/dotnet/runtime/commit/31d5d23e9c6f3da877343ccb020e85ca9f136c05</property> + </attribute> + </assembly> + + <assembly fullname="System.Reflection.Metadata"> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2070</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Reflection.CustomAttribute.AddCustomAttributes(System.RuntimeType.ListBuilder`1@,System.Reflection.RuntimeModule,System.Int32,System.RuntimeType,System.Bool,System.RuntimeType.ListBuilder{System.Object})</property> + <property name="Justification">Suppressed in 7.0 for ref param changes: https://github.com/dotnet/runtime/commit/50d289cc2b945c8ee6b4cca5b71d8d137c09a762</property> + </attribute> + </assembly> + + <assembly fullname="System.Diagnostics.DiagnosticSource"> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2119</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform.#ctor(System.String,System.Int32,System.Int32,System.Diagnostics.DiagnosticSourceEventSource,System.Diagnostics.DiagnosticSourceEventSource.FilterAndTransform)</property> + <property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property> + </attribute> + </assembly> + + <assembly fullname="System.Runtime.Serialization.Formatters"> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2065</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(System.Type)</property> + <property name="Justification">Suppressed in 7.0 for dataflow improvements: https://github.com/dotnet/runtime/commit/2e353d18b81732133aadbee888a801fd9f935fbf</property> + </attribute> + </assembly> + + <assembly fullname="System.Text.Json"> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2055</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Text.Json.Serialization.Converters.FSharpTypeConverterFactory.CreateConverter(System.Type,System.Text.Json.JsonSerializerOptions)</property> + <property name="Justification">Suppressed in 7.0 for new constraint warning: https://github.com/dotnet/runtime/commit/31d5d23e9c6f3da877343ccb020e85ca9f136c05</property> + </attribute> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2070</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Text.Json.Serialization.Converters.EnumConverterFactory.GetEnumConverterType(System.Type)</property> + <property name="Justification">Suppressed in 7.0 for new constraint warning: https://github.com/dotnet/runtime/commit/31d5d23e9c6f3da877343ccb020e85ca9f136c05</property> + </attribute> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2070</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Text.Json.Serialization.Converters.NullableConverterFactory.GetNullableConverterType(System.Type)</property> + <property name="Justification">Suppressed in 7.0 for new constraint warning: https://github.com/dotnet/runtime/commit/31d5d23e9c6f3da877343ccb020e85ca9f136c05</property> + </attribute> + </assembly> + + <assembly fullname="System.Private.Xml"> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2118</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Xml.Serialization.TypeScope.#cctor</property> + <property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property> + </attribute> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2118</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Xml.Serialization.TypeScope.AddSoapEncodedTypes(System.String)</property> + <property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property> + </attribute> + </assembly> + + <assembly fullname="System.Private.DataContractSerialization"> + <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"> + <argument>ILLink</argument> + <argument>IL2118</argument> + <property name="Scope">member</property> + <property name="Target">M:System.Runtime.Serialization.DateTimeDataContract.#ctor</property> + <property name="Justification">Suppressed in 7.0 for compiler-generated code changes: https://github.com/dotnet/runtime/commit/4a79e0696b1e425a58d8f5104cc572f39dd3005ea</property> + </attribute> + </assembly> + +</linker>
\ No newline at end of file diff --git a/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets b/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets index 76cf47287..e69f49b54 100644 --- a/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets +++ b/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets @@ -205,6 +205,15 @@ Copyright (c) .NET Foundation. All rights reserved. <Warning Condition="'$(TrimmerDefaultAction)' != '' And $([MSBuild]::VersionGreaterThan('$(TargetFrameworkVersion)', '6.0'))" Text="Property 'TrimmerDefaultAction' is deprecated in .NET 7 and will be ignored. Use TrimMode instead." /> + <!-- Use a sidecar file to suppress warnings when targeting net6.0, for changes that added or changed warnings. --> + <ItemGroup Condition="$([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0'))"> + <_ILLinkSuppressions Include="$(MSBuildThisFileDirectory)6.0_suppressions.xml" /> + </ItemGroup> + + <PropertyGroup Condition="'@(_ILLinkSuppressions->Count())' != '0'"> + <_ExtraTrimmerArgs>$(_ExtraTrimmerArgs) --link-attributes "@(_ILLinkSuppressions->'%(Identity)', '" --link-attributes "')"</_ExtraTrimmerArgs> + </PropertyGroup> + <!-- Set up TrimMode and TrimmerDefaultAction. --> <PropertyGroup> <TrimMode Condition="'$(TrimMode)' == '' And $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '6.0'))">copyused</TrimMode> diff --git a/src/linker/Linker.Dataflow/MethodBodyScanner.cs b/src/linker/Linker.Dataflow/MethodBodyScanner.cs index 613d5e9ad..2e3f09d6c 100644 --- a/src/linker/Linker.Dataflow/MethodBodyScanner.cs +++ b/src/linker/Linker.Dataflow/MethodBodyScanner.cs @@ -1102,7 +1102,7 @@ namespace Mono.Linker.Dataflow for (int ilArgumentIndex = offset; ilArgumentIndex < methodArguments.Count; ilArgumentIndex++, parameterIndex++) { if (calledMethod.ParameterReferenceKind (ilArgumentIndex) is not (ReferenceKind.Ref or ReferenceKind.Out)) continue; - SingleValue newByRefValue = methodIsResolved + SingleValue newByRefValue = methodIsResolved && parameterIndex < calledMethodDefinition!.Parameters.Count ? _context.Annotations.FlowAnnotations.GetMethodParameterValue (calledMethodDefinition!, parameterIndex) : UnknownValue.Instance; StoreInReference (methodArguments[ilArgumentIndex], newByRefValue, callingMethodBody.Method, operation, locals, curBasicBlock, ref ipState); diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs index 8de080022..9629c54b6 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs @@ -43,6 +43,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow TestParameterOverwrite (typeof (TestType)); + TestVarargsMethod (typeof (TestType), __arglist (0, 1, 2)); + WriteCapturedParameter.Test (); } @@ -237,6 +239,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow type.GetFields (); } + static void TestVarargsMethod ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type, __arglist) + { + } + class WriteCapturedParameter { [ExpectedWarning ("IL2072", nameof (GetUnknownType), "parameter")] |