Skip to content

Commit

Permalink
Remove ILLink warnings from empty console app
Browse files Browse the repository at this point in the history
Also clean up some previously addressed warnings in the suppressions xml file.

Contributes to dotnet#45623
  • Loading branch information
eerhardt committed Dec 9, 2020
1 parent 8671a07 commit 3fd8366
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Reflection;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace System
{
Expand Down Expand Up @@ -77,6 +78,9 @@ private static bool InternalIsDefined(PropertyInfo element, Type attributeType,
return false;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern",
Justification = "rtPropAccessor.DeclaringType is guaranteed to have the specified property because " +
"rtPropAccessor.GetParentDefinition() returned a non-null MethodInfo.")]
private static PropertyInfo? GetParentDefinition(PropertyInfo property, Type[] propertyParameters)
{
Debug.Assert(property != null);
Expand Down Expand Up @@ -142,6 +146,9 @@ private static Attribute[] InternalGetCustomAttributes(EventInfo element, Type t
return attributes;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern",
Justification = "rtAdd.DeclaringType is guaranteed to have the specified event because " +
"rtAdd.GetParentDefinition() returned a non-null MethodInfo.")]
private static EventInfo? GetParentDefinition(EventInfo ev)
{
Debug.Assert(ev != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ internal static bool IncludeAccessor(MethodInfo? associate, bool nonPublic)

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "Module.ResolveMethod is marked as RequiresUnreferencedCode because it relies on tokens" +
"which are not guaranteed to be stable across trimming. So if somebody harcodes a token it could break." +
"The usage here is not like that as all these tokes come from existing metadata loaded from some IL" +
"which are not guaranteed to be stable across trimming. So if somebody hardcodes a token it could break." +
"The usage here is not like that as all these tokens come from existing metadata loaded from some IL" +
"and so trimming has no effect (the tokens are read AFTER trimming occured).")]
private static RuntimeMethodInfo? AssignAssociates(
int tkMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override Type MakeArrayType(int rank)
public override string? FullName => m_strFullQualName ??= TypeNameBuilder.ToString(this, TypeNameBuilder.Format.FullName);
public override string? Namespace => m_type.Namespace;
public override string? AssemblyQualifiedName => TypeNameBuilder.ToString(this, TypeNameBuilder.Format.AssemblyQualifiedName);
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:UnrecognizedReflectionPatter",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:UnrecognizedReflectionPattern",
Justification = "The entire TypeBuilderInstantiation is serving the MakeGenericType implementation. " +
"Currently this is not supported by linker. Once it is supported the outercall (Type.MakeGenericType)" +
"will validate that the types fullfill the necessary requirements of annotations on type parameters." +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public override Type? CatchType
{
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "Module.ResolveType is marked as RequiresUnreferencedCode because it relies on tokens" +
"which are not guaranteed to be stable across trimming. So if somebody harcodes a token it could break." +
"The usage here is not like that as all these tokes come from existing metadata loaded from some IL" +
"which are not guaranteed to be stable across trimming. So if somebody hardcodes a token it could break." +
"The usage here is not like that as all these tokens come from existing metadata loaded from some IL" +
"and so trimming has no effect (the tokens are read AFTER trimming occured).")]
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal RuntimeType GetTypeChecked()
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern bool IsInstanceOfType(RuntimeType type, [NotNullWhen(true)] object? o);

[RequiresUnreferencedCode("MakeGenericType cannot be statically analyzed. It's not possible to guarantee the availability of requirements of the generic type.")]
internal static Type GetTypeHelper(Type typeStart, Type[]? genericArgs, IntPtr pModifiers, int cModifiers)
{
Type type = typeStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4029,6 +4029,7 @@ private extern object InvokeDispMethod(
#endregion

#if FEATURE_COMINTEROP
[RequiresUnreferencedCode("The member might be removed")]
private object? ForwardCallToInvokeMember(
string memberName,
BindingFlags flags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -53,6 +54,7 @@ internal sealed class TypeNameParser : IDisposable
#endregion

#region Static Members
[RequiresUnreferencedCode("The type might be removed")]
internal static Type? GetType(
string typeName,
Func<AssemblyName, Assembly?>? assemblyResolver,
Expand Down Expand Up @@ -102,6 +104,7 @@ public void Dispose()
#endregion

#region private Members
[RequiresUnreferencedCode("The type might be removed")]
private unsafe Type? ConstructType(
Func<AssemblyName, Assembly?>? assemblyResolver,
Func<Assembly?, string, bool, Type?>? typeResolver,
Expand Down Expand Up @@ -216,6 +219,7 @@ public void Dispose()
return assembly;
}

[RequiresUnreferencedCode("The type might be removed")]
private static Type? ResolveType(Assembly? assembly, string[] names, Func<Assembly?, string, bool, Type?>? typeResolver, bool throwOnError, bool ignoreCase, ref StackCrawlMark stackMark)
{
Debug.Assert(names != null && names.Length > 0);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
<property name="Scope">member</property>
<property name="Target">M:System.Delegate.#ctor(System.Type,System.String)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Reflection.Associates.AssignAssociates(System.Int32,System.RuntimeType,System.RuntimeType)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
Expand All @@ -55,12 +49,6 @@
<property name="Scope">member</property>
<property name="Target">M:System.Reflection.Emit.ModuleBuilder.GetTypeToken(System.String)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Reflection.RuntimeExceptionHandlingClause.get_CatchType</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
Expand All @@ -73,12 +61,6 @@
<property name="Scope">member</property>
<property name="Target">M:System.StartupHookProvider.ProcessStartupHooks()</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.TypeNameParser.ResolveType(System.Reflection.Assembly,System.String[],System.Func{System.Reflection.Assembly,System.String,System.Boolean,System.Type},System.Boolean,System.Boolean,System.Threading.StackCrawlMark@)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2050</argument>
Expand Down Expand Up @@ -121,24 +103,6 @@
<property name="Scope">member</property>
<property name="Target">M:System.Reflection.Emit.TypeBuilder.GetMethod(System.Type,System.Reflection.MethodInfo)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2055</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Reflection.Emit.TypeBuilderInstantiation.Substitute(System.Type[])</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2055</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Reflection.SignatureTypeExtensions.TryMakeGenericType(System.Type,System.Type[])</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2055</argument>
<property name="Scope">member</property>
<property name="Target">M:System.RuntimeTypeHandle.GetTypeHelper(System.Type,System.Type[],System.IntPtr,System.Int32)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2057</argument>
Expand Down Expand Up @@ -211,12 +175,6 @@
<property name="Scope">member</property>
<property name="Target">M:System.Reflection.RuntimeAssembly.AddPublicNestedTypes(System.Type,System.Collections.Generic.List{System.Type},System.Collections.Generic.List{System.Exception})</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2070</argument>
<property name="Scope">member</property>
<property name="Target">M:System.RuntimeType.GetMethodBase(System.RuntimeType,System.RuntimeMethodHandleInternal)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2072</argument>
Expand Down Expand Up @@ -247,18 +205,6 @@
<property name="Scope">member</property>
<property name="Target">M:Internal.Runtime.InteropServices.ComponentActivator.InternalGetFunctionPointer(System.Runtime.Loader.AssemblyLoadContext,System.String,System.String,System.IntPtr)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2075</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Attribute.GetParentDefinition(System.Reflection.EventInfo)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2075</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Attribute.GetParentDefinition(System.Reflection.PropertyInfo,System.Type[])</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2075</argument>
Expand Down Expand Up @@ -295,12 +241,6 @@
<property name="Scope">member</property>
<property name="Target">M:System.StartupHookProvider.CallStartupHook(System.StartupHookProvider.StartupHookNameOrPath)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2075</argument>
<property name="Scope">member</property>
<property name="Target">M:System.TypeNameParser.ResolveType(System.Reflection.Assembly,System.String[],System.Func{System.Reflection.Assembly,System.String,System.Boolean,System.Type},System.Boolean,System.Boolean,System.Threading.StackCrawlMark@)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2077</argument>
Expand Down Expand Up @@ -337,11 +277,5 @@
<property name="Scope">member</property>
<property name="Target">M:System.Reflection.Emit.TypeBuilder.DefinePInvokeMethodHelper(System.String,System.String,System.String,System.Reflection.MethodAttributes,System.Reflection.CallingConventions,System.Type,System.Type[],System.Type[],System.Type[],System.Type[][],System.Type[][],System.Runtime.InteropServices.CallingConvention,System.Runtime.InteropServices.CharSet)</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2085</argument>
<property name="Scope">member</property>
<property name="Target">M:System.RuntimeType.ForwardCallToInvokeMember(System.String,System.Reflection.BindingFlags,System.Object,System.Object[],System.Boolean[],System.Int32[],System.Type[],System.Type)</property>
</attribute>
</assembly>
</linker>
2 changes: 2 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/AppDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ public void SetThreadPrincipal(IPrincipal principal)

// TODO: Remove these DynamicDependencyAttributes when https://github.com/mono/linker/issues/943 is fixed.
[DynamicDependency("GetDefaultInstance", "System.Security.Principal.GenericPrincipal", "System.Security.Claims")]
#if TARGET_WINDOWS
[DynamicDependency("GetDefaultInstance", "System.Security.Principal.WindowsPrincipal", "System.Security.Principal.Windows")]
#endif
internal IPrincipal? GetThreadPrincipal()
{
IPrincipal? principal = _defaultPrincipal;
Expand Down

0 comments on commit 3fd8366

Please sign in to comment.