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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public enum ExceptionStringID
InvalidProgramVararg,
InvalidProgramCallVirtFinalize,
InvalidProgramNativeCallable,
InvalidProgramCallAbstractMethod,
InvalidProgramCallVirtStatic,

// BadImageFormatException
BadImageFormatGeneric,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ private void ceeInfoGetCallInfo(
// a static method would have never found an instance method.
if (originalMethod.Signature.IsStatic && (flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_CALLVIRT) != 0)
{
throw new BadImageFormatException();
ThrowHelper.ThrowInvalidProgramException(ExceptionStringID.InvalidProgramCallVirtStatic, originalMethod);
}

exactType = type;
Expand Down Expand Up @@ -1037,15 +1037,15 @@ private void ceeInfoGetCallInfo(
// Static methods are always direct calls
directCall = true;
}
else if ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_CALLVIRT) == 0 || resolvedConstraint)
{
directCall = true;
}
else if (targetMethod.OwningType.IsInterface && targetMethod.IsAbstract)
{
// Backwards compat: calls to abstract interface methods are treated as callvirt
directCall = false;
}
else if ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_CALLVIRT) == 0 || resolvedConstraint)
{
directCall = true;
}
else
{
bool devirt;
Expand Down Expand Up @@ -1090,6 +1090,14 @@ private void ceeInfoGetCallInfo(

if (directCall)
{
// Direct calls to abstract methods are not allowed
if (targetMethod.IsAbstract &&
// Compensate for always treating delegates as direct calls above
!(((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_LDFTN) != 0) && ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_CALLVIRT) != 0) && !resolvedCallVirt))
{
ThrowHelper.ThrowInvalidProgramException(ExceptionStringID.InvalidProgramCallAbstractMethod, targetMethod);
}

bool allowInstParam = (flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_ALLOWINSTPARAM) != 0;

if (!allowInstParam && canonMethod.RequiresInstArg())
Expand Down