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

Include new warning codes in --notrimwarn and --noaotwarn #105049

Merged
merged 2 commits into from
Jul 18, 2024
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
Expand Up @@ -19,5 +19,6 @@ public class ILCompilerOptions
public List<string> SubstitutionFiles = new List<string> ();
public bool TreatWarningsAsErrors;
public Dictionary<int, bool> WarningsAsErrors = new Dictionary<int, bool> ();
public List<string> SuppressedWarningCategories = new List<string> ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using ILLink.Shared;
using Mono.Linker.Tests.Extensions;

namespace Mono.Linker.Tests.TestCasesRunner
Expand Down Expand Up @@ -186,6 +187,12 @@ public virtual void AddAdditionalArgument (string flag, string[] values)
}
}
}
else if (flag == "--notrimwarn") {
Options.SuppressedWarningCategories.Add(MessageSubCategory.TrimAnalysis);
}
else if (flag == "--noaotwarn") {
Options.SuppressedWarningCategories.Add(MessageSubCategory.AotAnalysis);
}
}

public virtual void ProcessTestInputAssembly (NPath inputAssemblyPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ILScanResults Trim (ILCompilerOptions options, TrimmingCustomizations? cu
options.SingleWarn,
singleWarnEnabledModules: Enumerable.Empty<string> (),
singleWarnDisabledModules: Enumerable.Empty<string> (),
suppressedCategories: Enumerable.Empty<string> (),
suppressedCategories: options.SuppressedWarningCategories,
treatWarningsAsErrors: options.TreatWarningsAsErrors,
warningsAsErrors: options.WarningsAsErrors);

Expand Down
6 changes: 4 additions & 2 deletions src/tools/illink/src/ILLink.Shared/DiagnosticId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public enum DiagnosticId
_unused_DynamicallyAccessedMembersOnTypeReferencesCompilerGeneratedMemberOnBase = 2120,
RedundantSuppression = 2121,
TypeNameIsNotAssemblyQualified = 2122,
_EndTrimAnalysisWarningsSentinel = 2123,
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to not specify the value - AFAIK C# should assign the next (+1) value automatically which would make this work nicely when we add a new one.


// Single-file diagnostic ids.
AvoidAssemblyLocationInSingleFile = 3000,
Expand All @@ -203,6 +204,7 @@ public enum DiagnosticId
GenericRecursionCycle = 3054,
CorrectnessOfAbstractDelegatesCannotBeGuaranteed = 3055,
RequiresDynamicCodeOnStaticConstructor = 3056,
_EndAotAnalysisWarningsSentinel = 3057,

// Feature guard diagnostic ids.
ReturnValueDoesNotMatchFeatureGuards = 4000,
Expand All @@ -227,9 +229,9 @@ public static string GetDiagnosticSubcategory (this DiagnosticId diagnosticId) =
2103 => MessageSubCategory.TrimAnalysis,
2106 => MessageSubCategory.TrimAnalysis,
2107 => MessageSubCategory.TrimAnalysis,
>= 2109 and <= 2121 => MessageSubCategory.TrimAnalysis,
>= 2109 and <= (int) DiagnosticId._EndTrimAnalysisWarningsSentinel => MessageSubCategory.TrimAnalysis,
Copy link
Member

Choose a reason for hiding this comment

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

Technically this should be just <

>= 3050 and <= 3052 => MessageSubCategory.AotAnalysis,
>= 3054 and <= 3055 => MessageSubCategory.AotAnalysis,
>= 3054 and <= (int) DiagnosticId._EndAotAnalysisWarningsSentinel => MessageSubCategory.AotAnalysis,
_ => MessageSubCategory.None,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
sbomer marked this conversation as resolved.
Show resolved Hide resolved
using System.Threading.Tasks;
using Xunit;

namespace ILLink.RoslynAnalyzer.Tests
{
public sealed partial class WarningsTests : LinkerTestBase
{

protected override string TestSuiteName => "Warnings";

[Fact (Skip = "Analyzers are disabled entirely by SuppressTrimAnalysisWarnings or SuppressAotAnalysisWarnings")]
public Task CanDisableWarningsByCategory ()
{
return RunTest ();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace ILLink.RoslynAnalyzer.Tests
public sealed partial class WarningsTests : LinkerTestBase
{

protected override string TestSuiteName => "Warnings";

[Fact]
public Task CanDisableWarnAsError ()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
Copy link
Member

Choose a reason for hiding this comment

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

Header?

Copy link
Member Author

Choose a reason for hiding this comment

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

I started from a copy of an existing test that didn't have a copyright header. A lot of our tests don't - I guess that should be fixed.

using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.Warnings
{
[ExpectedNoWarnings]
[SkipKeptItemsValidation]
[SetupLinkerArgument ("--notrimwarn")]
#if NATIVEAOT
[SetupLinkerArgument ("--noaotwarn")]
#endif
public class CanDisableWarningsByCategory
{
public static void Main ()
{
TestNonQualifiedType ();
RequiresDynamicCodeOnStaticConstructor.Test ();
}

static void TestNonQualifiedType ()
{
RequireAll ("Mono.Linker.Tests.Cases.Warnings.TypeDoesntExist");
}

class RequiresDynamicCodeOnStaticConstructor
{
class StaticConstructor
{
[RequiresDynamicCode (nameof (StaticConstructor))]
static StaticConstructor () { }
}

public static void Test () {
new StaticConstructor ();
}
}

static void RequireAll ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string s) {}
}
}
Loading