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
path: root/src
diff options
context:
space:
mode:
authorJeremi Kurdek <59935235+jkurdek@users.noreply.github.com>2022-08-26 00:29:50 +0300
committerGitHub <noreply@github.com>2022-08-26 00:29:50 +0300
commitce187dafefb9309e90546d5694de186de683488d (patch)
tree4c89848302b6c3468ab00d93b1022ffffdb9c313 /src
parent6c73ce6d6c4828e20a1e911127963e153bd7db00 (diff)
Do not report redundant suppressions on trimmed members (#2999)
* Test repro + fix * fix marked filter for events and properties * formatting fix * simplified Suppression constructor * Add more tests for events and properties
Diffstat (limited to 'src')
-rw-r--r--src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs20
-rw-r--r--src/linker/Linker/UnconditionalSuppressMessageAttributeState.cs13
2 files changed, 25 insertions, 8 deletions
diff --git a/src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs b/src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs
index 4bb15635c..0250dfeca 100644
--- a/src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs
+++ b/src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs
@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using ILLink.Shared;
+using Mono.Cecil;
namespace Mono.Linker.Steps
{
@@ -23,13 +24,30 @@ namespace Mono.Linker.Steps
// Suppressions targeting RedundantSuppression warning should not be reported.
redundantSuppressions = redundantSuppressions
.Where (suppression => ((DiagnosticId) suppression.SuppressMessageInfo.Id).GetDiagnosticCategory () == DiagnosticCategory.Trimming)
- .Where (suppression => ((DiagnosticId) suppression.SuppressMessageInfo.Id) != DiagnosticId.RedundantSuppression);
+ .Where (suppression => ((DiagnosticId) suppression.SuppressMessageInfo.Id) != DiagnosticId.RedundantSuppression)
+ .Where (suppression => ProviderIsMarked (suppression.Provider));
foreach (var suppression in redundantSuppressions) {
var source = context.Suppressions.GetSuppressionOrigin (suppression);
context.LogWarning (new MessageOrigin (source), DiagnosticId.RedundantSuppression, $"IL{suppression.SuppressMessageInfo.Id:0000}");
}
+
+ bool ProviderIsMarked (ICustomAttributeProvider provider)
+ {
+ if (provider is PropertyDefinition property) {
+ return (property.GetMethod != null && context.Annotations.IsMarked (property.GetMethod))
+ || (property.SetMethod != null && context.Annotations.IsMarked (property.SetMethod));
+ }
+
+ if (provider is EventDefinition @event) {
+ return (@event.AddMethod != null && context.Annotations.IsMarked (@event.AddMethod))
+ || (@event.InvokeMethod != null && context.Annotations.IsMarked (@event.InvokeMethod))
+ || (@event.RemoveMethod != null && context.Annotations.IsMarked (@event.RemoveMethod));
+ }
+
+ return context.Annotations.IsMarked (provider);
+ }
}
}
}
diff --git a/src/linker/Linker/UnconditionalSuppressMessageAttributeState.cs b/src/linker/Linker/UnconditionalSuppressMessageAttributeState.cs
index 168b1ef72..2aff747d8 100644
--- a/src/linker/Linker/UnconditionalSuppressMessageAttributeState.cs
+++ b/src/linker/Linker/UnconditionalSuppressMessageAttributeState.cs
@@ -19,14 +19,13 @@ namespace Mono.Linker
public class Suppression
{
public SuppressMessageInfo SuppressMessageInfo { get; }
- public bool Used { get; set; }
+ public bool Used { get; set; } = false;
public CustomAttribute OriginAttribute { get; }
public ICustomAttributeProvider Provider { get; }
- public Suppression (SuppressMessageInfo suppressMessageInfo, bool used, CustomAttribute originAttribute, ICustomAttributeProvider provider)
+ public Suppression (SuppressMessageInfo suppressMessageInfo, CustomAttribute originAttribute, ICustomAttributeProvider provider)
{
SuppressMessageInfo = suppressMessageInfo;
- Used = used;
OriginAttribute = originAttribute;
Provider = provider;
}
@@ -270,7 +269,7 @@ namespace Mono.Linker
if (!TryDecodeSuppressMessageAttributeData (ca, out var info))
continue;
- yield return new Suppression (info, used: false, originAttribute: ca, provider);
+ yield return new Suppression (info, originAttribute: ca, provider);
}
}
@@ -297,13 +296,13 @@ namespace Mono.Linker
var scope = info.Scope?.ToLower ();
if (info.Target == null && (scope == "module" || scope == null)) {
- yield return new Suppression (info, used: false, originAttribute: instance, provider);
+ yield return new Suppression (info, originAttribute: instance, provider);
continue;
}
switch (scope) {
case "module":
- yield return new Suppression (info, used: false, originAttribute: instance, provider);
+ yield return new Suppression (info, originAttribute: instance, provider);
break;
case "type":
@@ -312,7 +311,7 @@ namespace Mono.Linker
break;
foreach (var result in DocumentationSignatureParser.GetMembersForDocumentationSignature (info.Target, module, _context))
- yield return new Suppression (info, used: false, originAttribute: instance, result);
+ yield return new Suppression (info, originAttribute: instance, result);
break;
default: