Skip to content

Commit df9a908

Browse files
authored
Check return types in isCompatibleMethodGDV (#118027)
1 parent f736e4f commit df9a908

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/coreclr/jit/importercalls.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7243,6 +7243,38 @@ bool Compiler::isCompatibleMethodGDV(GenTreeCall* call, CORINFO_METHOD_HANDLE gd
72437243
CORINFO_ARG_LIST_HANDLE sigParam = sig.args;
72447244
unsigned numParams = sig.numArgs;
72457245
unsigned numArgs = 0;
7246+
7247+
var_types gdvType = JITtype2varType(sig.retType);
7248+
var_types callType = call->gtReturnType;
7249+
7250+
const bool sameRetTypes =
7251+
(genActualType(callType) == genActualType(gdvType)) || (varTypeIsStruct(callType) && varTypeIsStruct(gdvType));
7252+
if (!sameRetTypes)
7253+
{
7254+
JITDUMP("Incompatible method GDV: Return types do not match - bail out.\n");
7255+
return false;
7256+
}
7257+
7258+
if (varTypeIsStruct(gdvType))
7259+
{
7260+
assert(varTypeIsStruct(callType));
7261+
7262+
CORINFO_SIG_INFO callSig;
7263+
info.compCompHnd->getMethodSig(call->gtCallMethHnd, &callSig);
7264+
7265+
structPassingKind callRetKind;
7266+
structPassingKind gdvRetKind;
7267+
getReturnTypeForStruct(callSig.retTypeClass, call->GetUnmanagedCallConv(), &callRetKind);
7268+
getReturnTypeForStruct(sig.retTypeClass, call->GetUnmanagedCallConv(), &gdvRetKind);
7269+
7270+
if ((callRetKind != gdvRetKind) ||
7271+
!ClassLayout::AreCompatible(typGetObjLayout(callSig.retTypeClass), typGetObjLayout(sig.retTypeClass)))
7272+
{
7273+
JITDUMP("Incompatible method GDV: Return struct types do not match - bail out.\n");
7274+
return false;
7275+
}
7276+
}
7277+
72467278
for (CallArg& arg : call->gtArgs.Args())
72477279
{
72487280
switch (arg.GetWellKnownArg())

0 commit comments

Comments
 (0)