diff options
author | Jackson Schuster <jschuster@microsoft.com> | 2021-12-03 19:39:55 +0300 |
---|---|---|
committer | Jackson Schuster <jschuster@microsoft.com> | 2021-12-10 01:39:54 +0300 |
commit | 921b07f5c71fd28358952423f119ddd3edd4aa05 (patch) | |
tree | 0ddaae3f2413c31866a2fc79bcc4ec838f1e7e1e | |
parent | c6293114a2d7c5134382505c495895c1f336e09c (diff) |
Undo irrelevant changes from a separate bug fix
Resets the files changed in the fix for bug 2379. Previously this branch
was forked off that branch, but needed to be cleaned up to make this
branch only have the changes needed for bug 2378.
-rw-r--r-- | src/ILLink.RoslynAnalyzer/COMAnalyzer.cs | 5 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs | 13 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/ILLink.RoslynAnalyzer/COMAnalyzer.cs b/src/ILLink.RoslynAnalyzer/COMAnalyzer.cs index 8e7dfe82c..05e0aa097 100644 --- a/src/ILLink.RoslynAnalyzer/COMAnalyzer.cs +++ b/src/ILLink.RoslynAnalyzer/COMAnalyzer.cs @@ -18,6 +18,7 @@ namespace ILLink.RoslynAnalyzer private const string StructLayoutAttribute = nameof (StructLayoutAttribute); private const string DllImportAttribute = nameof (DllImportAttribute); private const string MarshalAsAttribute = nameof (MarshalAsAttribute); + private const string RequiresUnreferencedCodeAttribute = nameof (RequiresUnreferencedCodeAttribute); static readonly DiagnosticDescriptor s_correctnessOfCOMCannotBeGuaranteed = DiagnosticDescriptors.GetDiagnosticDescriptor (DiagnosticId.CorrectnessOfCOMCannotBeGuaranteed, helpLinkUri: "https://docs.microsoft.com/en-us/dotnet/core/deploying/trim-warnings/il2050"); @@ -39,6 +40,10 @@ namespace ILLink.RoslynAnalyzer if (!targetMethod.HasAttribute (DllImportAttribute)) return; + if (operationContext.ContainingSymbol is ISymbol containingSymbol && containingSymbol.HasAttribute(RequiresUnreferencedCodeAttribute)) { + return; + } + bool comDangerousMethod = IsComInterop (targetMethod.ReturnType); foreach (var parameter in targetMethod.Parameters) { comDangerousMethod |= IsComInterop (parameter); diff --git a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs index c652f26fd..a92e86945 100644 --- a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs +++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs @@ -30,6 +30,7 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings Call_CanSuppressWarningOnParameter (); Call_CanSuppressWarningOnReturnType (); Call_CanSuppressWithRequiresUnreferencedCode (); + Call_CanSuppressWithRequiresUnreferencedCodeInLambda (); Call_CanSuppressPInvokeWithRequiresUnreferencedCode (); Call_PInvokeWithRequiresUnreferencedCode (); } @@ -156,8 +157,6 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings static extern IFoo CanSuppressWarningOnReturnType (); [RequiresUnreferencedCode ("test")] - // Bug https://github.com/dotnet/linker/issues/2378 - [ExpectedWarning ("IL2050", ProducedBy = ProducedBy.Analyzer)] static void Call_CanSuppressWithRequiresUnreferencedCode () { CanSuppressWithRequiresUnreferencedCode (null); @@ -167,8 +166,6 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings static extern void CanSuppressWithRequiresUnreferencedCode (IFoo foo); [RequiresUnreferencedCode ("test")] - // Bug https://github.com/dotnet/linker/issues/2378 - [ExpectedWarning ("IL2050", ProducedBy = ProducedBy.Analyzer)] static void Call_CanSuppressPInvokeWithRequiresUnreferencedCode () { CanSuppressPInvokeWithRequiresUnreferencedCode (null); @@ -178,6 +175,14 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings [DllImport ("Foo")] static extern void CanSuppressPInvokeWithRequiresUnreferencedCode (IFoo foo); + [RequiresUnreferencedCode ("test")] + static void Call_CanSuppressWithRequiresUnreferencedCodeInLambda () + { + var lambda = () => CanSuppressWithRequiresUnreferencedCode (null); + lambda (); + } + + [ExpectedWarning ("IL2050")] [ExpectedWarning ("IL2026")] static void Call_PInvokeWithRequiresUnreferencedCode () |