Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ILLink warnings from empty console app #45808

Merged
merged 3 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

[AttributeUsage(AttributeTargets.Property, Inherited = true)]
class FooAttribute : Attribute{ }
[AttributeUsage(AttributeTargets.Property, Inherited = true)]
class BarAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Property, Inherited = true)]
class BazAttribute : Attribute { }

class Base
{
[Foo]
public virtual int X { get; }
}

class Mid : Base
{
[Bar]
public override int X => base.X;
}

class Derived : Mid
{
[Baz]
public override int X => base.X;
}

class Program
{
static int Main(string[] args)
{
int numAttributes = Attribute.GetCustomAttributes(typeof(Derived).GetProperty("X"), inherit: true).Length;
if (numAttributes == 3)
{
return 100;
}

return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<TestConsoleAppSourceFiles Include="DebuggerTypeProxyAttributeTests.cs" />
<TestConsoleAppSourceFiles Include="DefaultValueAttributeCtorTest.cs" />
<TestConsoleAppSourceFiles Include="GenericArraySortHelperTest.cs" />
<TestConsoleAppSourceFiles Include="InheritedAttributeTests.cs" />
<TestConsoleAppSourceFiles Include="InterfacesOnArrays.cs" />
<TestConsoleAppSourceFiles Include="StackFrameHelperTest.cs">
<!-- There is a bug with the linker where it is corrupting the pdbs while trimming
Expand Down
1 change: 0 additions & 1 deletion src/libraries/illink-sharedframework.targets
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@

<!-- Collate CoreLib suppression XML files not bin-placed in earlier per-library linker run. CoreLib doesn't use bin-place logic. -->
<_SuppressionsXmls Include="$(CoreLibSharedILLinkSuppressionsFilesPrefix).xml" />
<_SuppressionsXmls Condition="'$(TargetOS)' != 'windows'" Include="$(CoreLibSharedILLinkSuppressionsFilesPrefix).NonWindows.xml" />

<!-- netstandard2.1-only System.ComponentModel.Annotations XML file is not bin-placed during -allConfigurations builds
due to the linker not being run on the assembly (eng\illink.targets). Manually include it. -->
Expand Down