diff options
author | Vitek Karas <10670590+vitek-karas@users.noreply.github.com> | 2022-07-01 12:05:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-01 12:05:31 +0300 |
commit | e4d85757ab8a6841efef85b8ab678dfb412faec6 (patch) | |
tree | ccf24a683d9b8ff09f29ac9241a9d5908a24feec /test/Mono.Linker.Tests.Cases/DataFlow | |
parent | bc46e445deb1411cc597019d693ddc5b4e5e24f4 (diff) |
Small updates to help with linker->aot port (#2873)
* Move GetDiagnosticCategory into shared code
* Describe the intent around usage of DiagnosticContext in a comment
* Minor fix in MessageOrigin GetHasCode
* Add tests for patterns which NativeAOT had trouble with
Linker changes made for https://github.com/dotnet/runtime/pull/71485
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/DataFlow')
4 files changed, 76 insertions, 10 deletions
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs index 7f73071d4..46120679c 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/AttributeConstructorDataflow.cs @@ -16,8 +16,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow { [KeptAttributeAttribute (typeof (KeepsPublicConstructorAttribute))] [KeptAttributeAttribute (typeof (KeepsPublicMethodsAttribute))] + [KeptAttributeAttribute (typeof (TypeArrayAttribute))] [KeepsPublicConstructor (typeof (ClassWithKeptPublicConstructor))] [KeepsPublicMethods ("Mono.Linker.Tests.Cases.DataFlow.AttributeConstructorDataflow+ClassWithKeptPublicMethods")] + [TypeArray (new Type[] { typeof (AttributeConstructorDataflow) })] // Trimmer only for now - https://github.com/dotnet/linker/issues/2273 [ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethods--", ProducedBy = ProducedBy.Trimmer)] public static void Main () @@ -109,5 +111,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow public int Field; } } + + [Kept] + [KeptBaseType (typeof (Attribute))] + class TypeArrayAttribute : Attribute + { + [Kept] + public TypeArrayAttribute (Type[] types) // This should not trigger data flow analysis of the parameter + { + } + } } } diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/AttributeFieldDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/AttributeFieldDataflow.cs index 44c857b74..2cac037c5 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/AttributeFieldDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/AttributeFieldDataflow.cs @@ -16,8 +16,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow { [KeptAttributeAttribute (typeof (KeepsPublicConstructorsAttribute))] [KeptAttributeAttribute (typeof (KeepsPublicMethodsAttribute))] + [KeptAttributeAttribute (typeof (TypeArrayAttribute))] [KeepsPublicConstructors (Type = typeof (ClassWithKeptPublicConstructor))] - [KeepsPublicMethods ("Mono.Linker.Tests.Cases.DataFlow.AttributeFieldDataflow+ClassWithKeptPublicMethods")] + [KeepsPublicMethods (Type = "Mono.Linker.Tests.Cases.DataFlow.AttributeFieldDataflow+ClassWithKeptPublicMethods")] + [TypeArray (Types = new Type[] { typeof (AttributeFieldDataflow) })] // Trimmer only for now - https://github.com/dotnet/linker/issues/2273 [ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethods--", ProducedBy = ProducedBy.Trimmer)] public static void Main () @@ -46,12 +48,14 @@ namespace Mono.Linker.Tests.Cases.DataFlow class KeepsPublicMethodsAttribute : Attribute { [Kept] - public KeepsPublicMethodsAttribute ( - [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] - [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] - string type) + public KeepsPublicMethodsAttribute () { } + + [Kept] + [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + public string Type; } [Kept] @@ -74,5 +78,18 @@ namespace Mono.Linker.Tests.Cases.DataFlow public static void KeptMethod () { } static void Method () { } } + + [Kept] + [KeptBaseType (typeof (Attribute))] + class TypeArrayAttribute : Attribute + { + [Kept] + public TypeArrayAttribute () + { + } + + [Kept] + public Type[] Types; + } } } diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs index e6848fa5d..1b10390ea 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs @@ -16,8 +16,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow { [KeptAttributeAttribute (typeof (KeepsPublicConstructorsAttribute))] [KeptAttributeAttribute (typeof (KeepsPublicMethodsAttribute))] + [KeptAttributeAttribute (typeof (TypeArrayAttribute))] [KeepsPublicConstructors (Type = typeof (ClassWithKeptPublicConstructor))] - [KeepsPublicMethods ("Mono.Linker.Tests.Cases.DataFlow.AttributePropertyDataflow+ClassWithKeptPublicMethods")] + [KeepsPublicMethods (Type = "Mono.Linker.Tests.Cases.DataFlow.AttributePropertyDataflow+ClassWithKeptPublicMethods")] + [TypeArray (Types = new Type[] { typeof (AttributePropertyDataflow) })] // Trimmer only for now - https://github.com/dotnet/linker/issues/2273 [ExpectedWarning ("IL2026", "--ClassWithKeptPublicMethods--", ProducedBy = ProducedBy.Trimmer)] public static void Main () @@ -47,12 +49,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow class KeepsPublicMethodsAttribute : Attribute { [Kept] - public KeepsPublicMethodsAttribute ( - [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] - [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] - string type) + public KeepsPublicMethodsAttribute () { } + + [field: Kept] + [Kept] + [KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + public string Type { get; [Kept] set; } } [Kept] @@ -75,5 +80,19 @@ namespace Mono.Linker.Tests.Cases.DataFlow public static void KeptMethod () { } static void Method () { } } + + [Kept] + [KeptBaseType (typeof (Attribute))] + class TypeArrayAttribute : Attribute + { + [Kept] + public TypeArrayAttribute () + { + } + + [field: Kept] + [Kept] + public Type[] Types { get; [Kept] set; } + } } } diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs index 0b05ededc..a16c455e8 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs @@ -126,10 +126,28 @@ namespace Mono.Linker.Tests.Cases.DataFlow static IntPtr GetDangerous () { return IntPtr.Zero; } [Kept] + [ExpectedWarning ("IL2070")] + static unsafe void LocalStackAllocDeref (Type t) + { + // Code pattern from CoreLib which caused problems in AOT port + // so making sure we handle this correctly (that is without failing) + int buffSize = 256; + byte* stackSpace = stackalloc byte[buffSize]; + byte* buffer = stackSpace; + + byte* toFree = buffer; + buffer = null; + + // IL2070 - this is to make sure that DataFlow ran on the method's body + t.GetProperties (); + } + + [Kept] [ExpectedWarning ("IL2026")] public static void Test () { IntPtrDeref (); + LocalStackAllocDeref (null); } } } |