Skip to content

Commit 25d88b4

Browse files
Add a way to suppress all trimming warnings (#74137)
Fixes #73926. Also adding AOT analysis suppression for parity. I didn't port the warning level support because the compat kind of goes beyond that. We can revisit later if needed.
1 parent 63d369d commit 25d88b4

File tree

5 files changed

+37
-43
lines changed

5 files changed

+37
-43
lines changed

eng/testing/tests.singlefile.targets

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,13 @@
2626
<IlcBuildTasksPath>$(CoreCLRILCompilerDir)netstandard/ILCompiler.Build.Tasks.dll</IlcBuildTasksPath>
2727
<IlcSdkPath>$(CoreCLRAotSdkDir)</IlcSdkPath>
2828
<IlcFrameworkPath>$(NetCoreAppCurrentTestHostSharedFrameworkPath)</IlcFrameworkPath>
29-
<NoWarn>$(NoWarn);IL3050;IL3051;IL3052;IL3054;IL3055;IL1005;IL3002</NoWarn>
29+
<NoWarn>$(NoWarn);IL1005;IL3002</NoWarn>
3030
<TrimMode>partial</TrimMode>
31-
<TrimmerSingleWarn>false</TrimmerSingleWarn>
3231
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
32+
<SuppressAotAnalysisWarnings>true</SuppressAotAnalysisWarnings>
3333

3434
<!-- Forced by ILLink targets; we should fix the SDK -->
3535
<SelfContained>true</SelfContained>
36-
37-
<!-- Works around https://github.com/dotnet/runtime/issues/73926 -->
38-
<!-- RequiresUnreferenceCodeAttribute method called -->
39-
<NoWarn>$(NoWarn);IL2026;IL2116</NoWarn>
40-
<!-- Invalid use of DynamicallyAccessedMembersAttribute -->
41-
<NoWarn>$(NoWarn);IL2041;IL2042;IL2043;IL2056</NoWarn>
42-
<!-- Reference to removed attribute type -->
43-
<NoWarn>$(NoWarn);IL2045</NoWarn>
44-
<!-- RequiresUnreferencedCodeAttribute mismatch on virtual override -->
45-
<NoWarn>$(NoWarn);IL2046</NoWarn>
46-
<!-- COM marshalling warning -->
47-
<NoWarn>$(NoWarn);IL2050</NoWarn>
48-
<!-- Reflection intrinsics with unknown arguments -->
49-
<NoWarn>$(NoWarn);IL2032;IL2055;IL2057;IL2058;IL2059;IL2060;IL2061;IL2096</NoWarn>
50-
<!-- Unknown values passed to locations with DynamicallyAccessedMemberTypes -->
51-
<NoWarn>$(NoWarn);IL2062;IL2063;IL2064;IL2065;IL2066</NoWarn>
52-
<!-- Unsatisfied DynamicallyAccessedMembers requirements -->
53-
<NoWarn>$(NoWarn);IL2067;IL2068;IL2069;IL2070;IL2071;IL2072;IL2073;IL2074;IL2075;IL2076;IL2077;IL2078;IL2079;IL2080;IL2081;IL2082;IL2083;IL2084;IL2085;IL2086;IL2087;IL2088;IL2089;IL2090;IL2091</NoWarn>
54-
<!-- DynamicallyAccessedMembersAttribute mismatch on virtual override -->
55-
<NoWarn>$(NoWarn);IL2092;IL2093;IL2094;IL2095</NoWarn>
56-
<!-- DynamicallyAccessedMembersAttribute used on unsupported member -->
57-
<NoWarn>$(NoWarn);IL2097;IL2098;IL2099;IL2106</NoWarn>
58-
<!-- Unknown value passed to Expression.Property -->
59-
<NoWarn>$(NoWarn);IL2103</NoWarn>
60-
<!-- Multiple methods associated with state machine type or user method -->
61-
<NoWarn>$(NoWarn);IL2107;IL2117</NoWarn>
62-
<!-- Unannotated type derived from base type with RequiresUnreferencedCode -->
63-
<NoWarn>$(NoWarn);IL2109</NoWarn>
64-
<!-- Reflection access to members with DynamicallyAccessedMembers requirements -->
65-
<NoWarn>$(NoWarn);IL2110;IL2111;IL2114;IL2115</NoWarn>
66-
<!-- Reflection access to members with RequiresUnreferencedCode -->
67-
<NoWarn>$(NoWarn);IL2112;IL2113</NoWarn>
68-
<!-- Reflection access to compiler-generated code -->
69-
<NoWarn>$(NoWarn);IL2118;IL2119;IL2120</NoWarn>
70-
7136
</PropertyGroup>
7237

7338
<Import Project="$(CoreCLRBuildIntegrationDir)Microsoft.DotNet.ILCompiler.SingleEntry.targets" Condition="'$(TestNativeAot)' == 'true'" />

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ The .NET Foundation licenses this file to you under the MIT license.
4949
<EventSourceSupport Condition="$(IlcDisableReflection) == 'true'">false</EventSourceSupport>
5050
</PropertyGroup>
5151

52+
<PropertyGroup Condition="'$(SuppressAotAnalysisWarnings)' == 'true'">
53+
<EnableAotAnalyzer Condition="'$(EnableAotAnalyzer)' == ''">false</EnableAotAnalyzer>
54+
</PropertyGroup>
55+
5256
<PropertyGroup>
5357
<NativeObjectExt Condition="'$(TargetOS)' == 'windows'">.obj</NativeObjectExt>
5458
<NativeObjectExt Condition="'$(TargetOS)' != 'windows'">.o</NativeObjectExt>
@@ -241,6 +245,8 @@ The .NET Foundation licenses this file to you under the MIT license.
241245
<IlcArg Condition="$(IlcDumpIL) == 'true'" Include="--ildump:$(NativeIntermediateOutputPath)%(ManagedBinary.Filename).il" />
242246
<IlcArg Condition="$(NoWarn) != ''" Include='--nowarn:"$([MSBuild]::Escape($(NoWarn)))"' />
243247
<IlcArg Condition="$(TrimmerSingleWarn) == 'true'" Include="--singlewarn" />
248+
<IlcArg Condition="$(SuppressTrimAnalysisWarnings) == 'true'" Include="--notrimwarn" />
249+
<IlcArg Condition="$(SuppressAotAnalysisWarnings) == 'true'" Include="--noaotwarn" />
244250
<IlcArg Condition="$(IlcTrimMetadata) == 'false'" Include="--reflectiondata:all" />
245251
<IlcArg Condition="'$(ControlFlowGuard)' == 'Guard' and '$(TargetOS)' == 'windows'" Include="--guard:cf" />
246252
<IlcArg Include="@(_IlcRootedAssemblies->'--root:%(Identity)')" />

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logger.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class Logger
2626
private readonly CompilerGeneratedState _compilerGeneratedState;
2727

2828
private readonly HashSet<int> _suppressedWarnings;
29+
private readonly HashSet<string> _suppressedCategories;
2930

3031
private readonly bool _isSingleWarn;
3132
private readonly HashSet<string> _singleWarnEnabledAssemblies;
@@ -44,7 +45,8 @@ public Logger(
4445
IEnumerable<int> suppressedWarnings,
4546
bool singleWarn,
4647
IEnumerable<string> singleWarnEnabledModules,
47-
IEnumerable<string> singleWarnDisabledModules)
48+
IEnumerable<string> singleWarnDisabledModules,
49+
IEnumerable<string> suppressedCategories)
4850
{
4951
_logWriter = writer;
5052
_compilerGeneratedState = ilProvider == null ? null : new CompilerGeneratedState(ilProvider, this);
@@ -53,15 +55,16 @@ public Logger(
5355
_isSingleWarn = singleWarn;
5456
_singleWarnEnabledAssemblies = new HashSet<string>(singleWarnEnabledModules, StringComparer.OrdinalIgnoreCase);
5557
_singleWarnDisabledAssemblies = new HashSet<string>(singleWarnDisabledModules, StringComparer.OrdinalIgnoreCase);
58+
_suppressedCategories = new HashSet<string>(suppressedCategories, StringComparer.Ordinal);
5659
}
5760

58-
public Logger(TextWriter writer, ILProvider ilProvider, bool isVerbose, IEnumerable<int> suppressedWarnings, bool singleWarn, IEnumerable<string> singleWarnEnabledModules, IEnumerable<string> singleWarnDisabledModules)
59-
: this(new TextLogWriter(writer), ilProvider, isVerbose, suppressedWarnings, singleWarn, singleWarnEnabledModules, singleWarnDisabledModules)
61+
public Logger(TextWriter writer, ILProvider ilProvider, bool isVerbose, IEnumerable<int> suppressedWarnings, bool singleWarn, IEnumerable<string> singleWarnEnabledModules, IEnumerable<string> singleWarnDisabledModules, IEnumerable<string> suppressedCategories)
62+
: this(new TextLogWriter(writer), ilProvider, isVerbose, suppressedWarnings, singleWarn, singleWarnEnabledModules, singleWarnDisabledModules, suppressedCategories)
6063
{
6164
}
6265

6366
public Logger(ILogWriter writer, ILProvider ilProvider, bool isVerbose)
64-
: this(writer, ilProvider, isVerbose, Array.Empty<int>(), singleWarn: false, Array.Empty<string>(), Array.Empty<string>())
67+
: this(writer, ilProvider, isVerbose, Array.Empty<int>(), singleWarn: false, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>())
6568
{
6669
}
6770

@@ -141,6 +144,8 @@ public void LogError(string text, int code, TypeSystemEntity origin, string subc
141144
public void LogError(TypeSystemEntity origin, DiagnosticId id, params string[] args) =>
142145
LogError(new MessageOrigin(origin), id, args);
143146

147+
internal bool IsWarningSubcategorySuppressed(string category) => _suppressedCategories.Contains(category);
148+
144149
internal bool IsWarningSuppressed(int code, MessageOrigin origin)
145150
{
146151
// This is causing too much noise

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logging/MessageContainer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ internal static MessageContainer CreateErrorMessage(MessageOrigin? origin, Diagn
125125
if (context.IsWarningSuppressed(code, origin))
126126
return null;
127127

128+
if (context.IsWarningSubcategorySuppressed(subcategory))
129+
return null;
130+
128131
if (TryLogSingleWarning(context, code, origin, subcategory))
129132
return null;
130133

@@ -139,6 +142,9 @@ internal static MessageContainer CreateErrorMessage(MessageOrigin? origin, Diagn
139142
if (context.IsWarningSuppressed((int)id, origin))
140143
return null;
141144

145+
if (context.IsWarningSubcategorySuppressed(subcategory))
146+
return null;
147+
142148
if (TryLogSingleWarning(context, (int)id, origin, subcategory))
143149
return null;
144150

src/coreclr/tools/aot/ILCompiler/Program.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515

1616
using Internal.CommandLine;
1717

18+
using ILCompiler.Dataflow;
19+
using ILLink.Shared;
20+
1821
using Debug = System.Diagnostics.Debug;
1922
using InstructionSet = Internal.JitInterface.InstructionSet;
20-
using ILCompiler.Dataflow;
2123

2224
namespace ILCompiler
2325
{
@@ -103,6 +105,8 @@ internal class Program
103105
private IReadOnlyList<string> _singleWarnEnabledAssemblies = Array.Empty<string>();
104106
private IReadOnlyList<string> _singleWarnDisabledAssemblies = Array.Empty<string>();
105107
private bool _singleWarn;
108+
private bool _noTrimWarn;
109+
private bool _noAotWarn;
106110

107111
private string _makeReproPath;
108112

@@ -228,6 +232,8 @@ private ArgumentSyntax ParseCommandLine(string[] args)
228232
syntax.DefineOption("nopreinitstatics", ref _noPreinitStatics, "Do not interpret static constructors at compile time");
229233
syntax.DefineOptionList("nowarn", ref _suppressedWarnings, "Disable specific warning messages");
230234
syntax.DefineOption("singlewarn", ref _singleWarn, "Generate single AOT/trimming warning per assembly");
235+
syntax.DefineOption("notrimwarn", ref _noTrimWarn, "Disable warnings related to trimming");
236+
syntax.DefineOption("noaotwarn", ref _noAotWarn, "Disable warnings related to AOT");
231237
syntax.DefineOptionList("singlewarnassembly", ref _singleWarnEnabledAssemblies, "Generate single AOT/trimming warning for given assembly");
232238
syntax.DefineOptionList("nosinglewarnassembly", ref _singleWarnDisabledAssemblies, "Expand AOT/trimming warnings for given assembly");
233239
syntax.DefineOptionList("directpinvoke", ref _directPInvokes, "PInvoke to call directly");
@@ -768,7 +774,13 @@ static string ILLinkify(string rootedAssembly)
768774
}
769775
ilProvider = new FeatureSwitchManager(ilProvider, featureSwitches);
770776

771-
var logger = new Logger(Console.Out, ilProvider, _isVerbose, ProcessWarningCodes(_suppressedWarnings), _singleWarn, _singleWarnEnabledAssemblies, _singleWarnDisabledAssemblies);
777+
var suppressedWarningCategories = new List<string>();
778+
if (_noTrimWarn)
779+
suppressedWarningCategories.Add(MessageSubCategory.TrimAnalysis);
780+
if (_noAotWarn)
781+
suppressedWarningCategories.Add(MessageSubCategory.AotAnalysis);
782+
783+
var logger = new Logger(Console.Out, ilProvider, _isVerbose, ProcessWarningCodes(_suppressedWarnings), _singleWarn, _singleWarnEnabledAssemblies, _singleWarnDisabledAssemblies, suppressedWarningCategories);
772784
CompilerGeneratedState compilerGeneratedState = new CompilerGeneratedState(ilProvider, logger);
773785

774786
var stackTracePolicy = _emitStackTraceData ?

0 commit comments

Comments
 (0)