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:
authorSven Boemer <sbomer@gmail.com>2022-03-19 01:03:13 +0300
committerGitHub <noreply@github.com>2022-03-19 01:03:13 +0300
commit947f66a100d05d7c829e53fe031a22e532cdb4d2 (patch)
tree14045a85c54a0e009565e8b944538426801b3ef3
parent1d774126b2aed67d61bb3bab54881555458e9452 (diff)
Fix empty/null handling for Type.BaseType intrinsic (#2694)
-rw-r--r--src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs4
2 files changed, 7 insertions, 3 deletions
diff --git a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
index ca33184a3..7c2af0307 100644
--- a/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
+++ b/src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
@@ -614,6 +614,11 @@ namespace ILLink.Shared.TrimAnalysis
// Type.BaseType
//
case IntrinsicId.Type_get_BaseType: {
+ if (instanceValue.IsEmpty ()) {
+ returnValue = MultiValueLattice.Top;
+ break;
+ }
+
foreach (var value in instanceValue) {
if (value is ValueWithDynamicallyAccessedMembers valueWithDynamicallyAccessedMembers) {
DynamicallyAccessedMemberTypes propagatedMemberTypes = DynamicallyAccessedMemberTypes.None;
@@ -650,6 +655,7 @@ namespace ILLink.Shared.TrimAnalysis
AddReturnValue (GetMethodReturnValue (calledMethod, returnValueDynamicallyAccessedMemberTypes));
} else if (value == NullValue.Instance) {
// Ignore nulls - null.BaseType will fail at runtime, but it has no effect on static analysis
+ returnValue ??= MultiValueLattice.Top;
continue;
} else {
// Unknown input - propagate a return value without any annotation - we know it's a Type but we know nothing about it
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
index 646994d11..270d43616 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
@@ -229,19 +229,17 @@ namespace Mono.Linker.Tests.Cases.DataFlow
type.BaseType.RequiresPublicMethods ();
}
- [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
static void TestNull ()
{
Type type = null;
type.BaseType.RequiresPublicMethods ();
}
- [ExpectedWarning ("IL2072", nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicMethods))]
static void TestNoValue ()
{
Type t = null;
Type noValue = Type.GetTypeFromHandle (t.TypeHandle);
- // Warns about the base type even though the above throws an exception at runtime.
+ // No warning because the above throws an exception at runtime.
noValue.BaseType.RequiresPublicMethods ();
}