Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
761aefb
Removed redundant suppressions from System.Private.CoreLib
jkurdek Aug 2, 2022
bbbc1e7
Removed redundant suppressions from System.Text.Json
jkurdek Aug 2, 2022
75abc6c
Removed redundant suppressions from System.Net.Http.Json
jkurdek Aug 2, 2022
060a478
Removed redundant suppressions from System.Private.DataContractSerial…
jkurdek Aug 2, 2022
0e6e96a
Removed redundant suppressions from System.Linq.Queryable
jkurdek Aug 2, 2022
8438461
Removed redundant suppressions from System.Reflection.DispatchProxy
jkurdek Aug 2, 2022
3d15fcc
Removed redundant suppressions from System.ComponentModel.TypeConverter
jkurdek Aug 2, 2022
e25790d
Removed redundant suppressions from System.Data.Common
jkurdek Aug 2, 2022
d6b594d
Removed redundant suppressions from Microsoft.CSharp
jkurdek Aug 2, 2022
32162d2
Removed redundant suppressions from Microsoft.VisualBasic.Core
jkurdek Aug 2, 2022
fc0e9d5
Removed redundant suppressions from System.Diagnostics.DiagnosticSource
jkurdek Aug 2, 2022
f3670c2
Apply suggestions from code review
jkurdek Aug 9, 2022
38b6f45
Suggestions from PR review
jkurdek Aug 9, 2022
5a6bb2e
removed omitted local function call
jkurdek Aug 9, 2022
e941d97
Enabled IL2121 in sfx
jkurdek Aug 12, 2022
bedf079
fix suppressions mono + X86
jkurdek Aug 18, 2022
393a6f2
Removed unnecessery suppressions around PInokes
jkurdek Aug 30, 2022
f8209e1
Fixed IL2121 warnings on Linux
jkurdek Aug 30, 2022
9cc221b
Apply suggestions from PR review
jkurdek Sep 6, 2022
d58df4f
Fix redundant suppression after dynamic code annotation
jkurdek Sep 6, 2022
9a0df91
Removed redundant suppressions NativeAot
jkurdek Sep 6, 2022
0c7165d
Reverted change in EventSource, put suppression in ifdef
jkurdek Sep 6, 2022
04dc831
Removed redundant suppressions found on mac/iOS
jkurdek Sep 7, 2022
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
Expand Up @@ -19,7 +19,7 @@
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:Internal.Runtime.InteropServices.InMemoryAssemblyLoader.LoadInMemoryAssembly(System.IntPtr,System.IntPtr)</property>
<property name="Target">M:Internal.Runtime.InteropServices.InMemoryAssemblyLoader.LoadInMemoryAssemblyInContextWhenSupported(System.IntPtr,System.IntPtr)</property>
<property name="Justification">This warning is left in the product so developers get an ILLink warning when trimming an app with Internal.Runtime.InteropServices.InMemoryAssemblyLoader.IsSupported=true.</property>
</attribute>
</assembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public static unsafe void LoadInMemoryAssembly(IntPtr moduleHandle, IntPtr assem
if (!IsSupported)
throw new NotSupportedException(SR.NotSupported_CppCli);

LoadInMemoryAssemblyInContextWhenSupported(moduleHandle, assemblyPath);
}

// The call to `LoadInMemoryAssemblyInContextImpl` will produce a warning IL2026.
// It is intentionally left in the product, so developers get a warning when trimming an app which enabled `Internal.Runtime.InteropServices.InMemoryAssemblyLoader.IsSupported`.
// For runtime build the warning is suppressed in the ILLink.Suppressions.LibraryBuild.xml, but we only want to suppress it if the feature is enabled (IsSupported is true).
// The call is extracted into a separate method which is the sole target of the suppression.
private static unsafe void LoadInMemoryAssemblyInContextWhenSupported(IntPtr moduleHandle, IntPtr assemblyPath)
{
#pragma warning disable IL2026 // suppressed in ILLink.Suppressions.LibraryBuild.xml
LoadInMemoryAssemblyInContextImpl(moduleHandle, assemblyPath);
#pragma warning restore IL2026
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ public override Type MakeArrayType(int rank)

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2063:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize always throwing method. https://github.com/mono/linker/issues/2025")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have references to this bug under src/coreclr/nativeaot as well - how was the redundant suppression analysis for NativeAOT done? I wonder why it didn't find those (they should be redundant because they were just a bug workaround).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redundant warning suppression detection has not been ported to nativeaot yet (#75201). The suppression you mentioned should be identified after the functionality is ported and run witihin nativeaot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has a change in src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/Assignability.cs - what mechanism was used to detect it?

(NativeAOT doesn't run on code that is unreferenced and doesn't have a "library mode" like illink does - so the ability to detect redundant suppressions is somewhat limited even if we were to port the feature - we would have to come up with an app that includes all the code in NativeAOT's libraries. It will only flag things that are used, making it easy for us to ship with an actual warning that only some customers will see - customers who happen to use that part of the library.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was detected because linker was used to "trim libraries for warnings" (The sfx project run of linker) and it was given the AOT corelib as input. Jeremi found out that this happens when you run build Clr.Aot+Libs -rc Debug -lc Release, in which case linker gets artifacts\bin\coreclr\windows.x64.Debug\aotsdk\System.Private.CoreLib.dll as one of the input assemblies.

As for the comment about NativeAOT not having libraries mode - that should not matter. The detection works in the "trim app" mode as well - it only reports redundant warnings on methods which were "marked".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was detected because linker was used to "trim libraries for warnings" (The sfx project run of linker) and it was given the AOT corelib as input

I see, yes, there can only be one corelib project for the libs partition but we have 3 in this repo.

The corelib is selected here:

<CoreLibProject Condition="'$(RuntimeFlavor)' == 'CoreCLR'">$([MSBuild]::NormalizePath('$(CoreClrProjectRoot)', 'System.Private.CoreLib', 'System.Private.CoreLib.csproj'))</CoreLibProject>
<CoreLibProject Condition="'$(RuntimeFlavor)' == 'Mono'">$([MSBuild]::NormalizePath('$(MonoProjectRoot)', 'System.Private.CoreLib', 'System.Private.CoreLib.csproj'))</CoreLibProject>
<CoreLibProject Condition="'$(UseNativeAotCoreLib)' == 'true'">$([MSBuild]::NormalizePath('$(CoreClrProjectRoot)', 'nativeaot', 'System.Private.CoreLib', 'src', 'System.Private.CoreLib.csproj'))</CoreLibProject>

public override Type GetInterface(string name, bool ignoreCase) { throw new NotSupportedException(); }

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ public override FieldInfo[] GetFields(BindingFlags bindingAttr)

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2063:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize always throwing method. https://github.com/mono/linker/issues/2025")]
public override Type GetInterface(string name, bool ignoreCase)
{
throw new NotSupportedException(SR.NotSupported_NonReflectedType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ public override Type? BaseType

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2063:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recognize always throwing method. https://github.com/mono/linker/issues/2025")]
public override Type GetInterface(string name, bool ignoreCase) { throw new NotSupportedException(); }

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,19 +789,12 @@ public static object BindToMoniker(string monikerName)
Release(bindctx);
}
}
// Revist after https://github.com/mono/linker/issues/1989 is fixed
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern",
Justification = "The calling method is annotated with RequiresUnreferencedCode")]
[LibraryImport(Interop.Libraries.Ole32)]
private static partial int CreateBindCtx(uint reserved, out IntPtr ppbc);

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern",
Justification = "The calling method is annotated with RequiresUnreferencedCode")]
[LibraryImport(Interop.Libraries.Ole32)]
private static partial int MkParseDisplayName(IntPtr pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IntPtr ppmk);

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern",
Justification = "The calling method is annotated with RequiresUnreferencedCode")]
[LibraryImport(Interop.Libraries.Ole32)]
private static partial int BindMoniker(IntPtr pmk, uint grfOpt, ref Guid iidResult, out IntPtr ppvResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3850,10 +3850,6 @@ private void CreateInstanceCheckThis()
throw new NotSupportedException(SR.Acc_CreateVoid);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2082:UnrecognizedReflectionPattern",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2085:UnrecognizedReflectionPattern",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
internal object? CreateInstanceImpl(
BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
{
Expand Down Expand Up @@ -3933,7 +3929,7 @@ private void CreateInstanceCheckThis()
}

// fast path??
instance = Activator.CreateInstance(this, nonPublic: true, wrapExceptions: wrapExceptions);
instance = CreateInstanceLocal(this, nonPublic: true, wrapExceptions: wrapExceptions);
}
else
{
Expand All @@ -3944,6 +3940,13 @@ private void CreateInstanceCheckThis()
}

return instance;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2082:UnrecognizedReflectionPattern",
Justification = "Implementation detail of Activator that linker intrinsically recognizes")]
object? CreateInstanceLocal(Type type, bool nonPublic, bool wrapExceptions)
{
return Activator.CreateInstance(this, nonPublic: true, wrapExceptions: wrapExceptions);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ internal static class Assignability
Justification = "Just instantiating over formals for desktop compat reasons")]
[UnconditionalSuppressMessage("AotAnalysis", "IL3050:AotUnfriendlyApi",
Justification = "Just instantiating over formals for desktop compat reasons")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "Looking at interface list is safe because we wouldn't remove reflection-visible interface from a reflection-visible type")]
public static bool IsAssignableFrom(Type toTypeInfo, Type fromTypeInfo)
{
if (toTypeInfo == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1834,8 +1834,6 @@ private static Expr BindStrBinOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG
Bind a shift operator: <<, >>. These can have integer or long first operands,
and second operand must be int.
*/
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "All types used here are builtin and will not be trimmed.")]
private static ExprBinOp BindShiftOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2)
{
Debug.Assert(ek == ExpressionKind.LeftShirt || ek == ExpressionKind.RightShift);
Expand Down Expand Up @@ -1902,8 +1900,6 @@ private ExprOperator BindBoolBitwiseOp(ExpressionKind ek, EXPRFLAG flags, Expr e
return BindBoolBinOp(this, ek, flags, expr1, expr2);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "All types used here are builtin and will not be trimmed.")]
private static Expr BindLiftedBoolBitwiseOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr expr1, Expr expr2) => null;

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Namespace Microsoft.VisualBasic.CompilerServices

<DllImport("oleaut32", PreserveSig:=False, CharSet:=CharSet.Unicode, EntryPoint:="VarNumFromParseNum")>
<RequiresUnreferencedCode("Marshalling COM Objects is not trim safe.")>
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:COMMarshalling",
Justification:="RequiresUnreferencedCode attribute currently doesn't suppress IL2050. This should be removed once it does. https://github.com/mono/linker/issues/1989")>
Friend Shared Function VarNumFromParseNum(
<MarshalAs(UnmanagedType.LPArray)> ByVal numprsPtr As Byte(),
<MarshalAs(UnmanagedType.LPArray)> ByVal DigitArray As Byte(),
Expand All @@ -41,8 +39,6 @@ Namespace Microsoft.VisualBasic.CompilerServices

<DllImport("oleaut32", PreserveSig:=False, CharSet:=CharSet.Unicode, EntryPoint:="VariantChangeType")>
<RequiresUnreferencedCode("Marshalling COM Objects is not trim safe.")>
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:COMMarshalling",
Justification:="RequiresUnreferencedCode attribute currently doesn't suppress IL2050. This should be removed once it does. https://github.com/mono/linker/issues/1989")>
Friend Shared Sub VariantChangeType(
<Out()> ByRef dest As Object,
<[In]()> ByRef Src As Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ Namespace Microsoft.VisualBasic
Return DirectCast(InvokeMethod("MsgBox", Prompt, Buttons, Title), MsgBoxResult)
End Function

<UnconditionalSuppressMessage("ReflectionAnalsys", "IL2075:UnrecognizedReflectionPattern",
Justification:="Trimmer warns because it can't see Microsoft.VisualBasic.Forms. If the assembly is there, the trimmer will be able to tell to preserve the method specified.")>
Private Function InvokeMethod(methodName As String, ParamArray args As Object()) As Object
Dim type As Type = Type.GetType("Microsoft.VisualBasic._Interaction, Microsoft.VisualBasic.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError:=False)
Dim method As MethodInfo = type?.GetMethod(methodName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ internal sealed partial class ReflectTypeDescriptionProvider : TypeDescriptionPr
// not merge them into the attribute set for a class.
private static readonly Type[] s_skipInterfaceAttributeList = InitializeSkipInterfaceAttributeList();

[UnconditionalSuppressMessage ("ReflectionAnalysis", "IL2045:AttributeRemoval",
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2121:RedundantSuppression",
Justification = "Removal of the attributes depends on the System.Runtime.InteropServices.BuiltInComInterop.IsSupported feature switch." +
"Building with feature switch enabled will not trigger attribute removal making the suppression unnecessary." +
"When disabled, the attributes are removed and the suppression is necessary.")]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2045:AttributeRemoval",
Justification = "The ComVisibleAttribute is marked for removal and it's referenced here. Since this array" +
"contains only attributes which are going to be ignored, removing such attribute" +
"will not break the functionality in any way.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2821,9 +2821,6 @@ private sealed class ComNativeDescriptorProxy : TypeDescriptionProvider
{
private readonly TypeDescriptionProvider _comNativeDescriptor;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072:UnrecognizedReflectionPattern",
Justification = "The trimmer can't find the ComNativeDescriptor type when System.Windows.Forms isn't available. " +
"When System.Windows.Forms is available, the type will be seen by the trimmer and the ctor will be preserved.")]
public ComNativeDescriptorProxy()
{
Type realComNativeDescriptor = Type.GetType("System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor, System.Windows.Forms", throwOnError: true)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,29 @@ private static class UnboxT<T>
{
internal static readonly Func<object, T?> s_unbox = Create();

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2090:MakeGenericMethod",
Justification = "'NullableField<TElem> where TElem : struct' implies 'TElem : new()'. Nullable does not make use of new() so it is safe.")]
private static Func<object, T?> Create()
{
if (typeof(T).IsValueType && default(T) == null)
{
if (!RuntimeFeature.IsDynamicCodeSupported)
return NullableFieldUsingReflection;

return CreateWhenDynamicCodeSupported();
}
return NonNullableField;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2090:MakeGenericMethod",
Justification = "'NullableField<TElem> where TElem : struct' implies 'TElem : new()'. Nullable does not make use of new() so it is safe." +
"The warning is only issued when IsDynamicCodeSupported is true.")]
static Func<object, T?> CreateWhenDynamicCodeSupported()
{
#pragma warning disable IL3050 // There is a path that is safe for AOT executed when IsDynamicCodeSupported is false.
return typeof(UnboxT<T>)
.GetMethod("NullableField", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)!
.MakeGenericMethod(Nullable.GetUnderlyingType(typeof(T))!)
.CreateDelegate<Func<object, T>>();
.GetMethod("NullableField", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)!
.MakeGenericMethod(Nullable.GetUnderlyingType(typeof(T))!)
.CreateDelegate<Func<object, T>>();
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
}
return NonNullableField;
}

private static T? NonNullableField(object value)
Expand Down
2 changes: 0 additions & 2 deletions src/libraries/System.Data.Common/src/System/Data/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6925,8 +6925,6 @@ internal void EvaluateExpressions()
}
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "This is unsafe only when columns have associated expression. All ways to add such expression are marked unsafe.")]
internal void EvaluateExpressions(DataRow row, DataRowAction action, List<DataRow>? cachedRows)
{
// evaluate all expressions for specified row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,7 @@ private void Dispose()
Interlocked.CompareExchange(ref _implicitTransformsTable,
new ConcurrentDictionary<Type, TransformSpec?>(1, 8), null);
}
implicitTransforms = _implicitTransformsTable.GetOrAdd(argType, type => MakeImplicitTransformsWrapper(type));

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "The Morph method has RequiresUnreferencedCode, but the trimmer can't see through lamdba calls.")]
static TransformSpec? MakeImplicitTransformsWrapper(Type transformType) => MakeImplicitTransforms(transformType);
implicitTransforms = _implicitTransformsTable.GetOrAdd(argType, MakeImplicitTransforms);
}

// implicitTransformas now fetched from cache or constructed, use it to Fetch all the implicit fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,24 @@ internal void MoveRule(int i)
}
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod",
Justification = "UpdateDelegates methods don't have ILLink annotations.")]
internal T MakeUpdateDelegate()
{
Type target = typeof(T);
MethodInfo invoke = target.GetInvokeMethod();

if (System.Linq.Expressions.LambdaExpression.CanCompileToIL
&& target.IsGenericType && IsSimpleSignature(invoke, out Type[] args))
{
return MakeUpdateDelegateWhenCanCompileToIL();
}

s_cachedNoMatch = CreateCustomNoMatchDelegate(invoke);
return CreateCustomUpdateDelegate(invoke);


[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod",
Justification = "UpdateDelegates methods don't have ILLink annotations.")]
T MakeUpdateDelegateWhenCanCompileToIL()
{
MethodInfo? method = null;
MethodInfo? noMatchMethod = null;
Expand All @@ -306,10 +315,10 @@ internal T MakeUpdateDelegate()
s_cachedNoMatch = (T)(object)noMatchMethod!.MakeGenericMethod(args).CreateDelegate(target);
return (T)(object)method.MakeGenericMethod(args).CreateDelegate(target);
}
}

s_cachedNoMatch = CreateCustomNoMatchDelegate(invoke);
return CreateCustomUpdateDelegate(invoke);
s_cachedNoMatch = CreateCustomNoMatchDelegate(invoke);
return CreateCustomUpdateDelegate(invoke);
}
}

private static bool IsSimpleSignature(MethodInfo invoke, out Type[] sig)
Expand Down
Loading