Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to do typeof of function pointers #67573

Merged
merged 1 commit into from
Apr 8, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId lookupKind, object t
switch (lookupKind)
{
case ReadyToRunHelperId.TypeHandle:
return NodeFactory.ConstructedTypeSymbol((TypeDesc)targetOfLookup);
return NodeFactory.ConstructedTypeSymbol(WithoutFunctionPointerType((TypeDesc)targetOfLookup));
case ReadyToRunHelperId.NecessaryTypeHandle:
return NecessaryTypeSymbolIfPossible((TypeDesc)targetOfLookup);
return NecessaryTypeSymbolIfPossible(WithoutFunctionPointerType((TypeDesc)targetOfLookup));
case ReadyToRunHelperId.TypeHandleForCasting:
{
var type = (TypeDesc)targetOfLookup;
Expand Down Expand Up @@ -419,6 +419,10 @@ public GenericDictionaryLookup ComputeGenericLookup(MethodDesc contextMethod, Re
return GenericDictionaryLookup.CreateHelperLookup(contextSource, lookupKind, targetOfLookup);
}

// CoreCLR compat - referring to function pointer types handled as IntPtr. No MethodTable for function pointers for now.
private static TypeDesc WithoutFunctionPointerType(TypeDesc type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there more places where this should be done for consistency?

For example, does enumeration of method argument types using reflection return IntPtr too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have tests so I would rather not spend time on that. We also don't have test for arrays of function pointers that do something atrocious. This is just to make a test pass.

We could also just delete it because the test is very likely not testing what its author intended, or block it on #11354.

=> type.IsFunctionPointer ? type.Context.GetWellKnownType(WellKnownType.IntPtr) : type;

public bool IsFatPointerCandidate(MethodDesc containingMethod, MethodSignature signature)
{
// Unmanaged calls are never fat pointers
Expand Down