Skip to content

Commit

Permalink
More thoroughly check for function pointers (#81344)
Browse files Browse the repository at this point in the history
Fixes #81117.
  • Loading branch information
MichalStrehovsky authored Jan 30, 2023
1 parent 56f6609 commit fea626a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
{
// Runtime reflection stack needs to obtain the type handle of the field
// (but there's no type handles for function pointers)
TypeDesc fieldTypeToCheck = _field.FieldType;
while (fieldTypeToCheck.IsParameterizedType)
fieldTypeToCheck = ((ParameterizedType)fieldTypeToCheck).ParameterType;
static bool ContainsFunctionPointers(TypeDesc type)
{
if (type.IsParameterizedType)
return ContainsFunctionPointers(((ParameterizedType)type).ParameterType);
foreach (TypeDesc instArg in type.Instantiation)
if (ContainsFunctionPointers(instArg))
return true;
return type.IsFunctionPointer;
}

if (!fieldTypeToCheck.IsFunctionPointer)
if (!ContainsFunctionPointers(_field.FieldType))
dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ static void AddSignatureDependency(ref DependencyList dependencies, NodeFactory

// Function pointers are not supported yet.
// https://github.com/dotnet/runtime/issues/71883
if (type.IsFunctionPointer)
static bool ContainsFunctionPointers(TypeDesc type)
{
if (type.IsParameterizedType)
return ContainsFunctionPointers(((ParameterizedType)type).ParameterType);
foreach (TypeDesc instArg in type.Instantiation)
if (ContainsFunctionPointers(instArg))
return true;
return type.IsFunctionPointer;
}
if (ContainsFunctionPointers(type))
return;

TypeDesc canonType = type.ConvertToCanonForm(CanonicalFormKind.Specific);
Expand Down

0 comments on commit fea626a

Please sign in to comment.