Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Analyzer suppression test fix - #2584

Merged
LakshanF merged 4 commits into
dotnet:feature/damAnalyzerfrom
LakshanF:Wrn2
Feb 8, 2022
Merged

LakshanF merged 4 commits into
dotnet:feature/damAnalyzerfrom
LakshanF:Wrn2

Conversation

@LakshanF

@LakshanF LakshanF commented Feb 4, 2022 •

Copy link
Copy Markdown
Contributor

Fix for #2579, Roslyn handles UnconditionalSuppressMessage on its own and we are not planning to add any special handling. The PR addresses the following 3 exceptions from the test bed.

@vitek-karas

Copy link
Copy Markdown
Member

SuppressWarningsInMembersAndTypesUsingTarget: Analyzer was generating couple of 2026 warnings that seems reasonable. Suppressed them

If we think that the warning is valid and linker doesn't produce it then it's a bug in the linker. Somebody needs to investigate why the linker doesn't warn in this case.

@LakshanF

LakshanF commented Feb 4, 2022

Copy link
Copy Markdown
Contributor Author

The reason the linker doesn't warn seems to be because we have SkipKeptItemsValidation on the test and linker's ResultChecker skips validation for the extra 2026 warnings needed. I was being a little lazy trying to understand the goal of this test with this combination of warning mix but will take a closer look at the intent of the test

@vitek-karas

Copy link
Copy Markdown
Member

SkipKeptItemsValidation should have nothing to do with warnings - this is weird.

@tlakollo

tlakollo commented Feb 5, 2022

Copy link
Copy Markdown
Contributor

This test is failing because it doesn't expect RUC from Expression.Call(). In runtime Expression.Call() is annotated with RUC (https://github.com/dotnet/runtime/blob/895c99cc502913fd7393b95af7cae5b9e6fbdea3/src/libraries/System.Linq.Expressions/ref/System.Linq.Expressions.cs#L439). Linker has intrinsics for handling it and that's why it doesn't warn. What I think the fix should be:

  • Add Expression.Call into RequiresUnreferencedCodeAnalyzer ReportSpecialIncompatibleMembersDiagnostic list of methods, next to MakeGenericMethod and MakeGenericType.

@tlakollo

tlakollo commented Feb 5, 2022

Copy link
Copy Markdown
Contributor

I was looking that currently the analyzer does the same with calls to System.Type.GetType (its annotated with RUC in runtime https://github.com/dotnet/runtime/blob/main/src/coreclr/System.Private.CoreLib/src/System/Type.CoreCLR.cs and we have an intrinsic that 'knows better' how to handle it) it might be worth it to just check all intrisics and reuse the logic from the shared project in ReportSpecialIncompatibleMembersDiagnostic.

@LakshanF
LakshanF requested a review from tlakollo February 6, 2022 19:22
var expressionCallType = compilation.GetTypeByMetadataName ("System.Linq.Expressions.Expression");
if (expressionCallType != null) {
incompatibleMembers.AddRange (expressionCallType.GetMembers ("Call").OfType<IMethodSymbol> ()
.Where (m => m.Parameters.Length == 4 && m.Parameters[0] is IParameterSymbol parameterSymbol

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The list of incompatible member purposes is to say "RequiresUnreferencedCodeAnalyzer please don't analyze this call" then the dataflow will handle the intrinsic and decide if it needs to warn or not. You are restricting the number of parameters and type of the parameter, which means that RequiresUnreferencedCodeAnalyzer will only bypass that case and for everything else will warn. Im afraid that dataflow will do something similar and we end up generating two warnings, I think what we want is:

- incompatibleMembers.AddRange (expressionCallType.GetMembers ("Call").OfType<IMethodSymbol> ()
-					.Where (m => m.Parameters.Length == 4 && m.Parameters[0] is IParameterSymbol parameterSymbol
-					&& parameterSymbol.Type?.ContainingNamespace?.Name == "System" && parameterSymbol.Type?.Name == "Type"));
+ incompatibleMembers.AddRange (expressionCallType.GetMembers ("Call").OfType<IMethodSymbol> ());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

unfortunately, there are lots of these Call methods and only 1 should be handled intrinsically. The code mimics the linker version. There are some other expression members that need special handling and I'm taking a look at those as part of #2578

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think #2578 will require a more general solution but I am fine with this change doing the minimum necessary to get the suppression tests working.

@sbomer sbomer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @LakshanF!

var expressionCallType = compilation.GetTypeByMetadataName ("System.Linq.Expressions.Expression");
if (expressionCallType != null) {
incompatibleMembers.AddRange (expressionCallType.GetMembers ("Call").OfType<IMethodSymbol> ()
.Where (m => m.Parameters.Length == 4 && m.Parameters[0] is IParameterSymbol parameterSymbol

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think #2578 will require a more general solution but I am fine with this change doing the minimum necessary to get the suppression tests working.

@LakshanF
LakshanF merged commit b96c89a into dotnet:feature/damAnalyzer Feb 8, 2022
@LakshanF
LakshanF deleted the Wrn2 branch February 8, 2022 17:57
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
* warning suppression test fix

* FB

* fb - missed a duplicated check

Commit migrated from dotnet/linker@b96c89a
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants