From bee7f73564e495e6ab8627e7c595dacc32a4b096 Mon Sep 17 00:00:00 2001 From: Vitek Karas Date: Thu, 17 Jun 2021 14:04:44 +0200 Subject: Warning suppressions in compiler generated code (#2075) This change implements the following high-level functionality: * `UnconditionalSuppressMessage` applies to the entire method body even for iterators, async methods * `RequiresUnreferencedCode` automatically suppresses trim analysis warnings from entire method body for iterators, async methods Solution approach: * Detect compiler generated code by using the `IteratorStateMachineAttribute`, `AsyncStateMachineAttribute` and `AyncIteratorStateMachineAttribute`. * When a method which is compiler generated (detected by looing for `<` in its name) is processed the original "user method" is determined by looking for a method with the "state machine" attribute pointing to the compiler generated type. * This information is cached to avoid duplication of relatively expensive detection logic. * Looks for `UnconditionalSuppressMessage` and `RequriesUnreferencedCode` in: * If the warning origin is not a compiler generated code - simply use the warning origin (method) - existing behavior * If the warning origin is compiler generated use both the origin as well as the user defined method (non-compiler-generated) which is the source of the code for the compiler generated origin This is done by storing additional `SuppressionContextMember` on `MessageOrigin` which should always point to non-compiler-generated item. Added lot of new tests for these scenarios. This implements warning suppression part of https://github.com/mono/linker/issues/2001 for state machines. --- .../Assertions/ExpectedWarningAttribute.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/Mono.Linker.Tests.Cases.Expectations/Assertions') diff --git a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs index 85bd85d67..04ba3fdcb 100644 --- a/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs +++ b/test/Mono.Linker.Tests.Cases.Expectations/Assertions/ExpectedWarningAttribute.cs @@ -18,5 +18,7 @@ namespace Mono.Linker.Tests.Cases.Expectations.Assertions // Set to true if the warning only applies to global analysis (ILLinker, as opposed to Roslyn Analyzer) public bool GlobalAnalysisOnly { get; set; } + + public bool CompilerGeneratedCode { get; set; } } } -- cgit v1.2.3