Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ILLink.Shared/TrimAnalysis/HandleCallAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@ public bool Invoke (MethodProxy calledMethod, MultiValue instanceValue, IReadOnl
// 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;
Expand Down Expand Up @@ -580,6 +585,7 @@ public bool Invoke (MethodProxy calledMethod, MultiValue instanceValue, IReadOnl
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,17 @@ static void TestAnnotatedAndUnannotated (
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 ();
}

Expand Down