diff options
Diffstat (limited to 'src/linker/Linker.Steps')
-rw-r--r-- | src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs | 13 | ||||
-rw-r--r-- | src/linker/Linker.Steps/LinkAttributesParser.cs | 22 | ||||
-rw-r--r-- | src/linker/Linker.Steps/MarkStep.cs | 3 |
3 files changed, 20 insertions, 18 deletions
diff --git a/src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs b/src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs index ade9de9d9..4bb15635c 100644 --- a/src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs +++ b/src/linker/Linker.Steps/CheckSuppressionsDispatcher.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using ILLink.Shared; -using Mono.Cecil; namespace Mono.Linker.Steps { @@ -23,16 +22,14 @@ namespace Mono.Linker.Steps // Suppressions targeting warning caused by anything but the linker should not be reported. // 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).GetDiagnosticCategory () == DiagnosticCategory.Trimming) + .Where (suppression => ((DiagnosticId) suppression.SuppressMessageInfo.Id) != DiagnosticId.RedundantSuppression); - foreach (var (provider, suppressMessageInfo) in redundantSuppressions) { - var source = GetSuppresionProvider (provider); + foreach (var suppression in redundantSuppressions) { + var source = context.Suppressions.GetSuppressionOrigin (suppression); - context.LogWarning (new MessageOrigin (source), DiagnosticId.RedundantSuppression, $"IL{suppressMessageInfo.Id:0000}"); + context.LogWarning (new MessageOrigin (source), DiagnosticId.RedundantSuppression, $"IL{suppression.SuppressMessageInfo.Id:0000}"); } } - - private static ICustomAttributeProvider GetSuppresionProvider (ICustomAttributeProvider provider) => provider is ModuleDefinition module ? module.Assembly : provider; } } diff --git a/src/linker/Linker.Steps/LinkAttributesParser.cs b/src/linker/Linker.Steps/LinkAttributesParser.cs index d297ab5b7..81b89e292 100644 --- a/src/linker/Linker.Steps/LinkAttributesParser.cs +++ b/src/linker/Linker.Steps/LinkAttributesParser.cs @@ -38,9 +38,10 @@ namespace Mono.Linker.Steps static bool IsRemoveAttributeInstances (string attributeName) => attributeName == "RemoveAttributeInstances" || attributeName == "RemoveAttributeInstancesAttribute"; - CustomAttribute[]? ProcessAttributes (XPathNavigator nav, ICustomAttributeProvider provider) + (CustomAttribute[]? customAttributes, MessageOrigin[]? origins) ProcessAttributes (XPathNavigator nav, ICustomAttributeProvider provider) { - var builder = new ArrayBuilder<CustomAttribute> (); + var customAttributesBuilder = new ArrayBuilder<CustomAttribute> (); + var originsBuilder = new ArrayBuilder<MessageOrigin> (); foreach (XPathNavigator attributeNav in nav.SelectChildren ("attribute", string.Empty)) { if (!ShouldProcessElement (attributeNav)) continue; @@ -74,11 +75,12 @@ namespace Mono.Linker.Steps CustomAttribute? customAttribute = CreateCustomAttribute (attributeNav, attributeType); if (customAttribute != null) { _context.LogMessage ($"Assigning external custom attribute '{FormatCustomAttribute (customAttribute)}' instance to '{provider}'."); - builder.Add (customAttribute); + customAttributesBuilder.Add (customAttribute); + originsBuilder.Add (GetMessageOriginForPosition (attributeNav)); } } - return builder.ToArray (); + return (customAttributesBuilder.ToArray (), originsBuilder.ToArray ()); static string FormatCustomAttribute (CustomAttribute ca) { @@ -491,14 +493,14 @@ namespace Mono.Linker.Steps { Debug.Assert (_attributeInfo != null); foreach (XPathNavigator parameterNav in nav.SelectChildren ("parameter", string.Empty)) { - var attributes = ProcessAttributes (parameterNav, method); - if (attributes != null) { + var (attributes, origins) = ProcessAttributes (parameterNav, method); + if (attributes != null && origins != null) { string paramName = GetAttribute (parameterNav, "name"); foreach (ParameterDefinition parameter in method.Parameters) { if (paramName == parameter.Name) { if (parameter.HasCustomAttributes || _attributeInfo.CustomAttributes.ContainsKey (parameter)) LogWarning (parameterNav, DiagnosticId.XmlMoreThanOneValyForParameterOfMethod, paramName, method.GetDisplayName ()); - _attributeInfo.AddCustomAttributes (parameter, attributes); + _attributeInfo.AddCustomAttributes (parameter, attributes, origins); break; } } @@ -572,9 +574,9 @@ namespace Mono.Linker.Steps void PopulateAttributeInfo (ICustomAttributeProvider provider, XPathNavigator nav) { Debug.Assert (_attributeInfo != null); - var attributes = ProcessAttributes (nav, provider); - if (attributes != null) - _attributeInfo.AddCustomAttributes (provider, attributes); + var (attributes, origins) = ProcessAttributes (nav, provider); + if (attributes != null && origins != null) + _attributeInfo.AddCustomAttributes (provider, attributes, origins); } } } diff --git a/src/linker/Linker.Steps/MarkStep.cs b/src/linker/Linker.Steps/MarkStep.cs index 81b4b5909..7dbede11d 100644 --- a/src/linker/Linker.Steps/MarkStep.cs +++ b/src/linker/Linker.Steps/MarkStep.cs @@ -281,6 +281,9 @@ namespace Mono.Linker.Steps // instead of the per-assembly stores. foreach (var (provider, annotations) in xmlInfo.CustomAttributes) Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes (provider, annotations); + + foreach (var (ca, origin) in xmlInfo.CustomAttributesOrigins) + Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add (ca, origin); } void Complete () |