@@ -474,7 +474,7 @@ namespace {
474474
475475 private:
476476 const TypeInfo &expand (SILParameterInfo param);
477- llvm::Type *addIndirectResult ();
477+ llvm::Type *addIndirectResult (SILType resultType );
478478
479479 SILFunctionConventions getSILFuncConventions () const {
480480 return SILFunctionConventions (FnType, IGM.getSILModule ());
@@ -532,9 +532,7 @@ namespace {
532532} // end namespace irgen
533533} // end namespace swift
534534
535- llvm::Type *SignatureExpansion::addIndirectResult () {
536- auto resultType = getSILFuncConventions ().getSILResultType (
537- IGM.getMaximalTypeExpansionContext ());
535+ llvm::Type *SignatureExpansion::addIndirectResult (SILType resultType) {
538536 const TypeInfo &resultTI = IGM.getTypeInfo (resultType);
539537 auto storageTy = resultTI.getStorageType ();
540538 addIndirectResultAttributes (IGM, Attrs, ParamIRTypes.size (), claimSRet (),
@@ -931,7 +929,7 @@ SignatureExpansion::expandDirectResult() {
931929 auto &ti = IGM.getTypeInfo (resultType);
932930 auto &native = ti.nativeReturnValueSchema (IGM);
933931 if (native.requiresIndirect ())
934- return std::make_pair (addIndirectResult (), nullptr );
932+ return std::make_pair (addIndirectResult (resultType ), nullptr );
935933
936934 // Disable the use of sret if we have a non-trivial direct result.
937935 if (!native.empty ()) CanUseSRet = false ;
@@ -1572,16 +1570,18 @@ void SignatureExpansion::expandExternalSignatureTypes() {
15721570
15731571 // If we return indirectly, that is the first parameter type.
15741572 if (returnInfo.isIndirect ()) {
1573+ auto resultType = getSILFuncConventions ().getSingleSILResultType (
1574+ IGM.getMaximalTypeExpansionContext ());
15751575 if (IGM.Triple .isWindowsMSVCEnvironment () &&
15761576 FnType->getRepresentation () ==
15771577 SILFunctionTypeRepresentation::CXXMethod) {
15781578 // Windows ABI places `this` before the
15791579 // returned indirect values.
15801580 emitArg (0 );
15811581 firstParamToLowerNormally = 1 ;
1582- addIndirectResult ();
1582+ addIndirectResult (resultType );
15831583 } else
1584- addIndirectResult ();
1584+ addIndirectResult (resultType );
15851585 }
15861586
15871587 // Use a special IR type for passing block pointers.
@@ -2007,7 +2007,7 @@ void SignatureExpansion::expandAsyncEntryType() {
20072007 auto &ti = IGM.getTypeInfo (resultType);
20082008 auto &native = ti.nativeReturnValueSchema (IGM);
20092009 if (native.requiresIndirect ())
2010- addIndirectResult ();
2010+ addIndirectResult (resultType );
20112011
20122012 // Add the indirect result types.
20132013 expandIndirectResults ();
@@ -3257,7 +3257,13 @@ llvm::CallBase *IRBuilder::CreateCallOrInvoke(
32573257 for (unsigned argIndex = 0 ; argIndex < func->arg_size (); ++argIndex) {
32583258 if (func->hasParamAttribute (argIndex, llvm::Attribute::StructRet)) {
32593259 llvm::AttrBuilder builder (func->getContext ());
3260- builder.addStructRetAttr (func->getParamStructRetType (argIndex));
3260+ // See if there is a sret parameter in the signature. There are cases
3261+ // where the called function has a sret parameter, but the signature
3262+ // doesn't (e.g., noreturn functions).
3263+ llvm::Type *ty = attrs.getParamStructRetType (argIndex);
3264+ if (!ty)
3265+ ty = func->getParamStructRetType (argIndex);
3266+ builder.addStructRetAttr (ty);
32613267 attrs = attrs.addParamAttributes (func->getContext (), argIndex, builder);
32623268 }
32633269 if (func->hasParamAttribute (argIndex, llvm::Attribute::ByVal)) {
0 commit comments