@@ -591,6 +591,10 @@ namespace {
591591 // / function type.
592592 void expandCoroutineContinuationType ();
593593
594+ // / Initializes the result type for functions with @guaranteed_addr return
595+ // / convention.
596+ void expandGuaranteedAddressResult ();
597+
594598 // Expand the components for the async continuation entrypoint of the
595599 // function type (the function to be called on returning).
596600 void expandAsyncReturnType ();
@@ -694,6 +698,10 @@ void SignatureExpansion::expandResult(
694698
695699 auto fnConv = getSILFuncConventions ();
696700
701+ if (fnConv.hasGuaranteedAddressResult ()) {
702+ return expandGuaranteedAddressResult ();
703+ }
704+
697705 // Disable the use of sret if we have multiple indirect results.
698706 if (fnConv.getNumIndirectSILResults () > 1 )
699707 CanUseSRet = false ;
@@ -911,6 +919,11 @@ void SignatureExpansion::expandCoroutineContinuationParameters() {
911919 }
912920}
913921
922+ void SignatureExpansion::expandGuaranteedAddressResult () {
923+ CanUseSRet = false ;
924+ ResultIRType = IGM.PtrTy ;
925+ }
926+
914927void SignatureExpansion::addAsyncParameters () {
915928 // using TaskContinuationFunction =
916929 // SWIFT_CC(swift)
@@ -3945,6 +3958,11 @@ void CallEmission::emitYieldsToExplosion(Explosion &out) {
39453958 }
39463959}
39473960
3961+ void CallEmission::emitGuaranteedAddressToExplosion (Explosion &out) {
3962+ auto call = emitCallSite ();
3963+ out.add (call);
3964+ }
3965+
39483966// / Emit the result of this call to an explosion.
39493967void CallEmission::emitToExplosion (Explosion &out, bool isOutlined) {
39503968 assert (state == State::Emitting);
@@ -3960,6 +3978,14 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
39603978
39613979 SILFunctionConventions fnConv (getCallee ().getSubstFunctionType (),
39623980 IGF.getSILModule ());
3981+
3982+ if (fnConv.hasGuaranteedAddressResult ()) {
3983+ assert (LastArgWritten == 0 &&
3984+ " @guaranteed_addr along with indirect result?" );
3985+ emitGuaranteedAddressToExplosion (out);
3986+ return ;
3987+ }
3988+
39633989 SILType substResultType =
39643990 fnConv.getSILResultType (IGF.IGM .getMaximalTypeExpansionContext ());
39653991
@@ -7019,6 +7045,16 @@ void irgen::emitYieldOnceCoroutineResult(IRGenFunction &IGF, Explosion &result,
70197045 }
70207046}
70217047
7048+ void irgen::emitGuaranteedAddressResult (IRGenFunction &IGF, Explosion &result,
7049+ SILType funcResultType,
7050+ SILType returnResultType) {
7051+ assert (funcResultType == returnResultType);
7052+ assert (funcResultType.isAddress ());
7053+ auto &Builder = IGF.Builder ;
7054+ Builder.CreateRet (result.claimNext ());
7055+ assert (result.empty ());
7056+ }
7057+
70227058FunctionPointer
70237059IRGenFunction::getFunctionPointerForResumeIntrinsic (llvm::Value *resume) {
70247060 auto *fnTy = llvm::FunctionType::get (
0 commit comments