Skip to content

Commit

Permalink
Fix linker ref param warnings (#70082)
Browse files Browse the repository at this point in the history
* Update dependencies from https://github.com/dotnet/linker build 20220523.1

Microsoft.NET.ILLink.Tasks
 From Version 7.0.100-1.22270.1 -> To Version 7.0.100-1.22273.1

* Update dependencies from https://github.com/dotnet/linker build 20220524.1

Microsoft.NET.ILLink.Tasks
 From Version 7.0.100-1.22270.1 -> To Version 7.0.100-1.22274.1

* Update dependencies from https://github.com/dotnet/linker build 20220525.1

Microsoft.NET.ILLink.Tasks
 From Version 7.0.100-1.22270.1 -> To Version 7.0.100-1.22275.1

* Update dependencies from https://github.com/dotnet/linker build 20220530.1

Microsoft.NET.ILLink.Tasks
 From Version 7.0.100-1.22270.1 -> To Version 7.0.100-1.22280.1

* Update dependencies from https://github.com/dotnet/linker build 20220531.1

Microsoft.NET.ILLink.Tasks
 From Version 7.0.100-1.22270.1 -> To Version 7.0.100-1.22281.1

* WIP

* Supress warnings produced by ref param dataflow

* Update comments and remove IL2118/9 suppressions

* whitespace

* Trailing whitespace

* PR feedback

* Fix wording

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Sven Boemer <sbomer@gmail.com>
  • Loading branch information
3 people authored Jun 7, 2022
1 parent 530359b commit 50d289c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>0864cc5539e0ddd109b443b0bee804878cd7ba76</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="7.0.100-1.22270.1">
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="7.0.100-1.22281.1">
<Uri>https://github.com/dotnet/linker</Uri>
<Sha>b0479355a71752de103a2aac89af5cdcdb0455ad</Sha>
<Sha>79b5653ccfd0663790b4dc4efe65c1285ede73fc</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.XHarness.TestRunners.Common" Version="1.0.0-prerelease.22270.1">
<Uri>https://github.com/dotnet/xharness</Uri>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<!-- Docs -->
<MicrosoftPrivateIntellisenseVersion>7.0.0-preview-20220429.1</MicrosoftPrivateIntellisenseVersion>
<!-- ILLink -->
<MicrosoftNETILLinkTasksVersion>7.0.100-1.22270.1</MicrosoftNETILLinkTasksVersion>
<MicrosoftNETILLinkTasksVersion>7.0.100-1.22281.1</MicrosoftNETILLinkTasksVersion>
<MicrosoftNETILLinkAnalyzerPackageVersion>$(MicrosoftNETILLinkTasksVersion)</MicrosoftNETILLinkAnalyzerPackageVersion>
<!-- ICU -->
<MicrosoftNETCoreRuntimeICUTransportVersion>7.0.0-preview.5.22269.3</MicrosoftNETCoreRuntimeICUTransportVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,10 @@ private EventBuilder DefineEventNoLock(string name, EventAttributes attributes,

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2083:UnrecognizedReflectionPattern",
Justification = "Reflection.Emit is not subject to trimming")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2068:UnrecognizedReflectionPattern",
Justification = "Reflection.Emit is not subject to trimming")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2069:UnrecognizedReflectionPattern",
Justification = "Reflection.Emit is not subject to trimming")]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
private TypeInfo? CreateTypeNoLock()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ private static object[] GetCustomAttributes(
return result;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2065:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:MethodParameterDoesntMeetThisParameterRequirements",
Justification = "Linker guarantees presence of all the constructor parameters, property setters and fields which are accessed by any " +
"attribute instantiation which is present in the code linker has analyzed." +
"As such the reflection usage in this method will never fail as those methods/fields will be present.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ internal static ReadOnlySpan<IntPtr> CopyRuntimeTypeHandles(RuntimeTypeHandle[]?
return outHandles;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:ParameterDoesntMeetParameterRequirements",
Justification = "The parameter 'type' is passed by ref to QCallTypeHandle which only instantiates" +
"the type using the public parameterless constructor and doesn't modify it")]
internal static object CreateInstanceForAnotherGenericParameter(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] RuntimeType type,
RuntimeType genericParameter)
Expand All @@ -257,6 +260,9 @@ internal static object CreateInstanceForAnotherGenericParameter(
return instantiatedObject!;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:ParameterDoesntMeetParameterRequirements",
Justification = "The parameter 'type' is passed by ref to QCallTypeHandle which only instantiates" +
"the type using the public parameterless constructor and doesn't modify it")]
internal static object CreateInstanceForAnotherGenericParameter(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] RuntimeType type,
RuntimeType genericParameter1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,10 @@ public static void ValidateMetadataType(
}
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2063:UnrecognizedReflectionPattern",
Justification = "The cache is a dictionary which is hard to annotate. All values in the cache" +
"have annotation All (since we only ever add attribute.MetadataClassType which has All)." +
"But the call to TryGetValue doesn't carry the annotation so this warns when trying" +
"to return value.")]
// Better "fix" for the missing annotation would be a local funcion
// `bool TryGetAssociatedMetadataTypeFromCache(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] out Type? associatedMetadataType)`
// With the suppression on it - since that would be much more localized.
// Unfortunately this currently doesn't work due to an issue in the trimmer
// https://github.com/dotnet/linker/issues/2632
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public static Type? GetAssociatedMetadataType(Type type)
{
Type? associatedMetadataType;
if (s_metadataTypeCache.TryGetValue(type, out associatedMetadataType))
if (TryGetAssociatedMetadataTypeFromCache(type, out Type? associatedMetadataType))
{
return associatedMetadataType;
}
Expand All @@ -140,6 +129,16 @@ public static void ValidateMetadataType(
}
s_metadataTypeCache.TryAdd(type, associatedMetadataType);
return associatedMetadataType;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:ParameterDoesntMeetParameterRequirements",
Justification = "The cache is a dictionary which is hard to annotate. All values in the cache" +
"have annotation All (since we only ever add attribute.MetadataClassType which has All)." +
"But the call to TryGetValue doesn't carry the annotation so this warns when trying" +
"to assign to the out parameter.")]
static bool TryGetAssociatedMetadataTypeFromCache(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] out Type? associatedMetadataType)
{
return s_metadataTypeCache.TryGetValue(type, out associatedMetadataType);
}
}

private static void CheckAssociatedMetadataType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2062</argument>
<argument>IL2067</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Resources.Extensions.PreserializedResourceWriter.AddResource(System.String,System.String,System.String)</property>
</attribute>
Expand Down

0 comments on commit 50d289c

Please sign in to comment.