Skip to content

Commit 06cab35

Browse files
committed
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.
1 parent 497ed57 commit 06cab35

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/NullableAnnotations.cs

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public static void Main ()
6565
GetUnderlyingTypeOnNonNullableKnownType.Test ();
6666
MakeGenericTypeWithUnknownValue (new object[2] { 1, 2 });
6767
MakeGenericTypeWithKnowAndUnknownArray ();
68+
69+
// Prevents optimizing away 'as Type' conversion.
70+
PreserveSystemType ();
6871
}
6972

7073
[Kept]
@@ -331,5 +334,11 @@ static void MakeGenericTypeWithKnowAndUnknownArray (Type[] unknownTypes = null,
331334
nullable.GetProperties (); // This works - we still know it's Nullable<>, so we can get its properties
332335
Nullable.GetUnderlyingType (nullable).GetFields (); // This must warn - since we have no idea what the underlying type is for the unknownTypes case
333336
}
337+
338+
[Kept]
339+
static void PreserveSystemType ()
340+
{
341+
typeof (Type).RequiresNonPublicConstructors ();
342+
}
334343
}
335344
}

Diff for: src/tools/illink/test/Mono.Linker.Tests.Cases/UnreachableBlock/ComplexConditions.cs

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Reflection.Emit;
33
using Mono.Linker.Tests.Cases.Expectations.Assertions;
4+
using Mono.Linker.Tests.Cases.Expectations.Helpers;
45
using Mono.Linker.Tests.Cases.Expectations.Metadata;
56

67
namespace Mono.Linker.Tests.Cases.UnreachableBlock
@@ -14,6 +15,9 @@ public static void Main ()
1415
{
1516
Test_1 (null);
1617
Test_2 (9);
18+
19+
// Prevents optimizing away 'is Type' check.
20+
PreserveSystemType ();
1721
}
1822

1923
[Kept]
@@ -100,5 +104,11 @@ static bool IsDynamicCodeSupported {
100104
static void Reached_1 ()
101105
{
102106
}
107+
108+
[Kept]
109+
static void PreserveSystemType ()
110+
{
111+
typeof (Type).RequiresNonPublicConstructors ();
112+
}
103113
}
104114
}

0 commit comments

Comments
 (0)