@@ -1471,9 +1471,15 @@ void SignatureExpansion::expandExternalSignatureTypes() {
14711471 // Generate function info for this signature.
14721472 auto extInfo = clang::FunctionType::ExtInfo ();
14731473
1474- auto &FI = clang::CodeGen::arrangeFreeFunctionCall (IGM.ClangCodeGen ->CGM (),
1475- clangResultTy, paramTys, extInfo,
1476- clang::CodeGen::RequiredArgs::All);
1474+ bool isCXXMethod =
1475+ FnType->getRepresentation () == SILFunctionTypeRepresentation::CXXMethod;
1476+ auto &FI = isCXXMethod ?
1477+ clang::CodeGen::arrangeCXXMethodCall (IGM.ClangCodeGen ->CGM (),
1478+ clangResultTy, paramTys, extInfo, {},
1479+ clang::CodeGen::RequiredArgs::All) :
1480+ clang::CodeGen::arrangeFreeFunctionCall (IGM.ClangCodeGen ->CGM (),
1481+ clangResultTy, paramTys, extInfo, {},
1482+ clang::CodeGen::RequiredArgs::All);
14771483 ForeignInfo.ClangInfo = &FI;
14781484
14791485 assert (FI.arg_size () == paramTys.size () &&
@@ -1595,9 +1601,7 @@ void SignatureExpansion::expandExternalSignatureTypes() {
15951601 if (returnInfo.isIndirect ()) {
15961602 auto resultType = getSILFuncConventions ().getSingleSILResultType (
15971603 IGM.getMaximalTypeExpansionContext ());
1598- if (IGM.Triple .isWindowsMSVCEnvironment () &&
1599- FnType->getRepresentation () ==
1600- SILFunctionTypeRepresentation::CXXMethod) {
1604+ if (returnInfo.isSRetAfterThis ()) {
16011605 // Windows ABI places `this` before the
16021606 // returned indirect values.
16031607 emitArg (0 );
@@ -2577,11 +2581,12 @@ class SyncCallEmission final : public CallEmission {
25772581
25782582 // Windows ABI places `this` before the
25792583 // returned indirect values.
2580- bool isThisFirst = IGF.IGM .Triple .isWindowsMSVCEnvironment ();
2581- if (!isThisFirst)
2584+ auto &returnInfo =
2585+ getCallee ().getForeignInfo ().ClangInfo ->getReturnInfo ();
2586+ if (returnInfo.isIndirect () && !returnInfo.isSRetAfterThis ())
25822587 passIndirectResults ();
25832588 adjusted.add (arg);
2584- if (isThisFirst )
2589+ if (returnInfo. isIndirect () && returnInfo. isSRetAfterThis () )
25852590 passIndirectResults ();
25862591 }
25872592
@@ -3171,9 +3176,10 @@ void CallEmission::emitToUnmappedMemory(Address result) {
31713176 assert (LastArgWritten == 1 && " emitting unnaturally to indirect result" );
31723177
31733178 Args[0 ] = result.getAddress ();
3174- if (IGF.IGM .Triple .isWindowsMSVCEnvironment () &&
3175- getCallee ().getRepresentation () ==
3176- SILFunctionTypeRepresentation::CXXMethod &&
3179+
3180+ auto *FI = getCallee ().getForeignInfo ().ClangInfo ;
3181+ if (FI && FI->getReturnInfo ().isIndirect () &&
3182+ FI->getReturnInfo ().isSRetAfterThis () &&
31773183 Args[1 ] == getCallee ().getCXXMethodSelf ()) {
31783184 // C++ methods in MSVC ABI pass `this` before the
31793185 // indirectly returned value.
@@ -3566,10 +3572,10 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
35663572 emitToMemory (temp, substResultTI, isOutlined);
35673573 return ;
35683574 }
3569- if (IGF. IGM . Triple . isWindowsMSVCEnvironment () &&
3570- getCallee ().getRepresentation () ==
3571- SILFunctionTypeRepresentation::CXXMethod &&
3572- substResultType.isVoid ()) {
3575+
3576+ auto *FI = getCallee ().getForeignInfo (). ClangInfo ;
3577+ if (FI && FI-> getReturnInfo (). isIndirect () &&
3578+ FI-> getReturnInfo (). isSRetAfterThis () && substResultType.isVoid ()) {
35733579 // Some C++ methods return a value but are imported as
35743580 // returning `Void` (e.g. `operator +=`). In this case
35753581 // we should allocate the correct temp indirect return
0 commit comments