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:
authorSven Boemer <sbomer@gmail.com>2022-03-24 18:34:48 +0300
committerGitHub <noreply@github.com>2022-03-24 18:34:48 +0300
commit7ef273a57f8e1b2f31792e9702bd1a8d6e9d5519 (patch)
tree948216d2cfa902de82d793bf340b4661df32001a
parent04c49c9d7c244d7c73d6dbb438c4885fa72e830b (diff)
Don't let RUC on cctor silence warnings (#2705)
* Don't let RUC on cctor silence warnings
-rw-r--r--src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs9
-rw-r--r--src/linker/Linker/Annotations.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnStaticConstructor.cs13
3 files changed, 21 insertions, 7 deletions
diff --git a/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs b/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs
index d536b4569..aaf80b725 100644
--- a/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs
+++ b/src/ILLink.RoslynAnalyzer/RequiresISymbolExtensions.cs
@@ -57,11 +57,12 @@ namespace ILLink.RoslynAnalyzer
if (member is ITypeSymbol)
return false;
- if (member.HasAttribute (requiresAttribute)
- || (member.ContainingType is ITypeSymbol containingType &&
- containingType.HasAttribute (requiresAttribute))) {
+ if (member.HasAttribute (requiresAttribute) && !member.IsStaticConstructor ())
return true;
- }
+
+ if (member.ContainingType is ITypeSymbol containingType && containingType.HasAttribute (requiresAttribute))
+ return true;
+
// Only check associated symbol if not override or virtual method
if (checkAssociatedSymbol && member is IMethodSymbol { AssociatedSymbol: { } associated } && associated.HasAttribute (requiresAttribute))
return true;
diff --git a/src/linker/Linker/Annotations.cs b/src/linker/Linker/Annotations.cs
index 7e8e16e43..d51c4ea48 100644
--- a/src/linker/Linker/Annotations.cs
+++ b/src/linker/Linker/Annotations.cs
@@ -618,8 +618,10 @@ namespace Mono.Linker
/// instance methods (not just statics and .ctors).</remarks>
internal bool IsMethodInRequiresUnreferencedCodeScope (MethodDefinition method)
{
- if (HasLinkerAttribute<RequiresUnreferencedCodeAttribute> (method) ||
- (method.DeclaringType is not null && HasLinkerAttribute<RequiresUnreferencedCodeAttribute> (method.DeclaringType)))
+ if (HasLinkerAttribute<RequiresUnreferencedCodeAttribute> (method) && !method.IsStaticConstructor ())
+ return true;
+
+ if (method.DeclaringType is not null && HasLinkerAttribute<RequiresUnreferencedCodeAttribute> (method.DeclaringType))
return true;
return false;
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnStaticConstructor.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnStaticConstructor.cs
index 9b4007a5b..a07ce5219 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnStaticConstructor.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresOnStaticConstructor.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
@@ -28,10 +28,14 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class StaticCtor
{
+ [ExpectedWarning ("IL2026", "--MethodWithRequires--")]
+ [ExpectedWarning ("IL3002", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
+ [ExpectedWarning ("IL3050", "--MethodWithRequires--", ProducedBy = ProducedBy.Analyzer)]
[ExpectedWarning ("IL2116", "StaticCtor..cctor()")]
[RequiresUnreferencedCode ("Message for --TestStaticCtor--")]
static StaticCtor ()
{
+ MethodWithRequires ();
}
}
@@ -123,5 +127,12 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
{
var x = TypeIsBeforeFieldInit.field + 42;
}
+
+ [RequiresUnreferencedCode ("--MethodWithRequires--")]
+ [RequiresAssemblyFiles ("--MethodWithRequires--")]
+ [RequiresDynamicCode ("--MethodWithRequires--")]
+ static void MethodWithRequires ()
+ {
+ }
}
}