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:
authorAndy Gocke <angocke@microsoft.com>2022-02-19 00:47:18 +0300
committerGitHub <noreply@github.com>2022-02-19 00:47:18 +0300
commiteaeebf7d7288cb9c57abccdbb4f800a41043a798 (patch)
tree022088000d0aecef328a7817b53f1336595d6e4f /test/Mono.Linker.Tests.Cases
parentf678247e45c54b82045c64861967b77b18f6d684 (diff)
parent119eec6a7ce1b864f40d77196eea2b8d754e50e0 (diff)
Merge branch 'main' into merge-damanalyzer
Diffstat (limited to 'test/Mono.Linker.Tests.Cases')
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs45
-rw-r--r--test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs51
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/ObjectGetType.cs51
-rw-r--r--test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs5
4 files changed, 150 insertions, 2 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs
index 379ff5293..31235e8bb 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/LocalDataFlow.cs
@@ -44,6 +44,9 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestNoWarningsInRUCMethod ();
TestNoWarningsInRUCType ();
+
+ // These are probably just bugs
+ TestBackwardEdgeWithLdElem ();
}
[ExpectedWarning ("IL2072",
@@ -393,6 +396,48 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
}
+ // https://github.com/dotnet/linker/issues/2624
+ // [ExpectedWarning ("IL2063")] // The types loaded from the array don't have annotations, so the "return" should warn
+ [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
+ public static Type TestBackwardEdgeWithLdElem (Type[] types = null)
+ {
+ Type resultType = null;
+ foreach (var type in types) {
+ resultType = type;
+ }
+
+ return resultType;
+ }
+
+ public static void RequireAll (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+ string type)
+ {
+ }
+
+ public static void RequirePublicFields (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
+ string type)
+ {
+ }
+
+ public static void RequireNonPublicMethods (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicMethods)]
+ string type)
+ {
+ }
+ public static void RequirePublicMethods (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
+ string type)
+ {
+ }
+
+ public static void RequirePublicConstructors (
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
+ string type)
+ {
+ }
+
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)]
public static string GetWithPublicFields ()
{
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 d64847908..4c513ba89 100644
--- a/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs
+++ b/test/Mono.Linker.Tests.Cases/Interop/PInvoke/Warnings/ComPInvokeWarning.cs
@@ -4,12 +4,14 @@ using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Text;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
[SkipKeptItemsValidation]
[ExpectedNoWarnings]
[KeptModuleReference ("Foo")]
+ [SetupCompileArgument ("/unsafe")]
class ComPInvokeWarning
{
[UnconditionalSuppressMessage ("trim", "IL2026")]
@@ -32,6 +34,9 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
Call_CanSuppressWithRequiresUnreferencedCode ();
Call_CanSuppressPInvokeWithRequiresUnreferencedCode ();
Call_PInvokeWithRequiresUnreferencedCode ();
+ Call_PInvokeWithVoidPointerArg ();
+ Call_PInvokeWithStructPointerArg ();
+ Call_PInvokeWithSequentialStructPointerArg ();
}
[ExpectedWarning ("IL2050")]
@@ -185,6 +190,38 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
[DllImport ("Foo")]
static extern void PInvokeWithRequiresUnreferencedCode (IFoo foo);
+ static unsafe void Call_PInvokeWithVoidPointerArg ()
+ {
+ PInvokeWithVoidPointerArg (null);
+ }
+
+ [DllImport ("Foo")]
+ static extern unsafe void PInvokeWithVoidPointerArg (void* arg);
+
+ static unsafe void Call_PInvokeWithStructPointerArg ()
+ {
+ PInvokeWithStructPointerArg (null);
+ }
+
+ [DllImport ("Foo")]
+ static extern unsafe ExplicitLayoutStruct* PInvokeWithStructPointerArg (ExplicitLayoutStruct* arg);
+
+ static unsafe void Call_PInvokeWithSequentialStructPointerArg ()
+ {
+ PInvokeWithSequentialStructPointerArg (null);
+ }
+
+ [DllImport ("Foo")]
+ static extern unsafe SequentialLayoutStruct* PInvokeWithSequentialStructPointerArg (SequentialLayoutStruct* arg);
+
+ static unsafe void Call_PInvokeWithAutoStructPointerArg ()
+ {
+ PInvokeWithAutoStructPointerArg (null);
+ }
+
+ [DllImport ("Foo")]
+ static extern unsafe AutoLayoutStruct* PInvokeWithAutoStructPointerArg (AutoLayoutStruct* arg);
+
interface IFoo { }
class TestSafeHandle : SafeHandle
@@ -230,5 +267,19 @@ namespace Mono.Linker.Tests.Cases.Interop.PInvoke.Warnings
{
}
+ [StructLayout (LayoutKind.Explicit)]
+ public struct ExplicitLayoutStruct
+ {
+ }
+
+ [StructLayout (LayoutKind.Sequential)]
+ public struct SequentialLayoutStruct
+ {
+ }
+
+ [StructLayout (LayoutKind.Auto)]
+ public struct AutoLayoutStruct
+ {
+ }
}
}
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/ObjectGetType.cs b/test/Mono.Linker.Tests.Cases/Reflection/ObjectGetType.cs
index 8ef343afa..c0b263a32 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/ObjectGetType.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/ObjectGetType.cs
@@ -51,6 +51,8 @@ namespace Mono.Linker.Tests.Cases.Reflection
ApplyingAnnotationIntroducesTypesToApplyAnnotationToEntireType.Test ();
EnumerationOverInstances.Test ();
+
+ DataFlowUnusedGetType.Test ();
}
[Kept]
@@ -1407,5 +1409,54 @@ namespace Mono.Linker.Tests.Cases.Reflection
}
}
}
+
+ [Kept]
+ class DataFlowUnusedGetType
+ {
+ [Kept]
+ [KeptMember (".ctor()")]
+ [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
+ class AnnotatedType
+ {
+ [RequiresUnreferencedCode ("AnnotatedType.Method")]
+ public void Method () { }
+ }
+
+ [Kept]
+ static AnnotatedType GetInstance () => new AnnotatedType ();
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
+ [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
+ class AnnotatedBase
+ {
+ }
+
+ class DerivedFromAnnotatedBase : AnnotatedBase
+ {
+ [RequiresUnreferencedCode ("DerivedFromAnnotatedBase.Method")]
+ public void Method () { }
+ }
+
+ [Kept]
+ static AnnotatedBase GetBaseInstance () => new AnnotatedBase ();
+
+ [Kept]
+ public static void Test ()
+ {
+ // Call GetType, but don't use it for any data flow related stuff (no reflection or annotations)
+ // Linker has an optimization which avoids marking the type for type hierarchy annotations in this case
+ var name = GetInstance ().GetType ().Name;
+
+ // Using GetType and isinst should not mark the type or apply the annotation either
+ // This is a specific test for a pattern we want the linker to trim correctly
+ // that is the type which is only referenced in the isinst in a condition like this should not be kept
+ if (GetBaseInstance ().GetType () is DerivedFromAnnotatedBase) {
+ Console.WriteLine ("Never get here");
+ }
+ }
+ }
}
}
diff --git a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
index 4ea17a38a..e7192de58 100644
--- a/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
+++ b/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInCompilerGeneratedCode.cs
@@ -982,9 +982,10 @@ namespace Mono.Linker.Tests.Cases.RequiresCapability
class SuppressInLambda
{
- // Requires doesn't propagate into lambdas
+ // Bug https://github.com/dotnet/linker/issues/2001
+ // Requires should propagate into lambdas
- // C# currently doesn't allow attributes on lambdas
+ // C# 10 allows attributes on lambdas
// - This would be useful as a workaround for the limitation as Requires could be applied to the lambda directly
// - Would be useful for testing - have to use the CompilerGeneratedCode = true trick instead