Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitek Karas <vitek.karas@microsoft.com>2021-06-17 15:04:44 +0300
committerGitHub <noreply@github.com>2021-06-17 15:04:44 +0300
commitbee7f73564e495e6ab8627e7c595dacc32a4b096 (patch)
treeefa4d4c7116898b736223e24b431843f124bb668 /test/Mono.Linker.Tests
parent4f68312aeb4b8b906bee4e06438020ad6721c522 (diff)
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.
Diffstat (limited to 'test/Mono.Linker.Tests')
-rw-r--r--test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
index b4508e15e..18a32880d 100644
--- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
+++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs
@@ -707,6 +707,7 @@ namespace Mono.Linker.Tests.TestCasesRunner
string fileName = (string) attr.GetPropertyValue ("FileName");
int? sourceLine = (int?) attr.GetPropertyValue ("SourceLine");
int? sourceColumn = (int?) attr.GetPropertyValue ("SourceColumn");
+ bool? isCompilerGeneratedCode = (bool?) attr.GetPropertyValue ("CompilerGeneratedCode");
int expectedWarningCodeNumber = int.Parse (expectedWarningCode.Substring (2));
var actualMethod = attrProvider as MethodDefinition;
@@ -751,6 +752,16 @@ namespace Mono.Linker.Tests.TestCasesRunner
if (!actualOrigin.ToString ().EndsWith (expectedOrigin, StringComparison.OrdinalIgnoreCase))
return false;
}
+ } else if (isCompilerGeneratedCode == true) {
+ MethodDefinition methodDefinition = mc.Origin?.MemberDefinition as MethodDefinition;
+ if (methodDefinition != null) {
+ string actualName = methodDefinition.DeclaringType.FullName + "." + methodDefinition.Name;
+ if (actualName.StartsWith (attrProvider.DeclaringType.FullName) &&
+ actualName.Contains ("<" + attrProvider.Name + ">"))
+ return true;
+ }
+
+ return false;
} else {
if (mc.Origin?.MemberDefinition?.FullName == attrProvider.FullName)
return true;