From 06cab3500454311b98c9d96284c746ffbf411c38 Mon Sep 17 00:00:00 2001 From: Sven Boemer Date: Fri, 6 Dec 2024 19:13:03 +0000 Subject: [PATCH] With https://github.com/dotnet/runtime/pull/106497/files, object.GetType is no longer an internalcall. This means we no longer mark the ctor of the return type, System.Type, so the type check removal optimization is kicking in where it didn't before. --- .../DataFlow/NullableAnnotations.cs | 9 +++++++++ .../UnreachableBlock/ComplexConditions.cs | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs index 8f11a98281eee7..29b8bf650cbffa 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs @@ -65,6 +65,9 @@ public static void Main () GetUnderlyingTypeOnNonNullableKnownType.Test (); MakeGenericTypeWithUnknownValue (new object[2] { 1, 2 }); MakeGenericTypeWithKnowAndUnknownArray (); + + // Prevents optimizing away 'as Type' conversion. + PreserveSystemType (); } [Kept] @@ -331,5 +334,11 @@ static void MakeGenericTypeWithKnowAndUnknownArray (Type[] unknownTypes = null, nullable.GetProperties (); // This works - we still know it's Nullable<>, so we can get its properties Nullable.GetUnderlyingType (nullable).GetFields (); // This must warn - since we have no idea what the underlying type is for the unknownTypes case } + + [Kept] + static void PreserveSystemType () + { + typeof (Type).RequiresNonPublicConstructors (); + } } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/ComplexConditions.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/ComplexConditions.cs index 68714608fcca98..4d2838c3b9ebfe 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/ComplexConditions.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/ComplexConditions.cs @@ -1,6 +1,7 @@ using System; using System.Reflection.Emit; using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Helpers; using Mono.Linker.Tests.Cases.Expectations.Metadata; namespace Mono.Linker.Tests.Cases.UnreachableBlock @@ -14,6 +15,9 @@ public static void Main () { Test_1 (null); Test_2 (9); + + // Prevents optimizing away 'is Type' check. + PreserveSystemType (); } [Kept] @@ -100,5 +104,11 @@ static bool IsDynamicCodeSupported { static void Reached_1 () { } + + [Kept] + static void PreserveSystemType () + { + typeof (Type).RequiresNonPublicConstructors (); + } } } \ No newline at end of file