@@ -575,6 +575,13 @@ static Address emitAddrOfContinuationNormalResultPointer(IRGenFunction &IGF,
575575 Address context) {
576576 assert (context.getType () == IGF.IGM .ContinuationAsyncContextPtrTy );
577577 auto offset = 5 * IGF.IGM .getPointerSize ();
578+ return IGF.Builder .CreateStructGEP (context, 4 , offset);
579+ }
580+
581+ static Address emitAddrOfContinuationErrorResultPointer (IRGenFunction &IGF,
582+ Address context) {
583+ assert (context.getType () == IGF.IGM .ContinuationAsyncContextPtrTy );
584+ auto offset = 4 * IGF.IGM .getPointerSize ();
578585 return IGF.Builder .CreateStructGEP (context, 3 , offset);
579586}
580587
@@ -693,7 +700,8 @@ void IRGenFunction::emitAwaitAsyncContinuation(
693700 Explosion &outDirectResult, llvm::BasicBlock *&normalBB,
694701 llvm::PHINode *&optionalErrorResult, llvm::BasicBlock *&optionalErrorBB) {
695702 assert (AsyncCoroutineCurrentContinuationContext && " no active continuation" );
696- auto pointerAlignment = IGM.getPointerAlignment ();
703+ Address continuationContext (AsyncCoroutineCurrentContinuationContext,
704+ IGM.getAsyncContextAlignment ());
697705
698706 // Call swift_continuation_await to check whether the continuation
699707 // has already been resumed.
@@ -703,11 +711,9 @@ void IRGenFunction::emitAwaitAsyncContinuation(
703711 // swift_continuation_await, emit the old inline sequence. This can
704712 // be removed as soon as we're sure that such SDKs don't exist.
705713 if (!useContinuationAwait) {
706- auto contAwaitSyncAddr = Builder.CreateStructGEP (
707- AsyncCoroutineCurrentContinuationContext->getType ()
708- ->getScalarType ()
709- ->getPointerElementType (),
710- AsyncCoroutineCurrentContinuationContext, 1 );
714+ auto contAwaitSyncAddr =
715+ Builder.CreateStructGEP (continuationContext, 2 ,
716+ 3 * IGM.getPointerSize ()).getAddress ();
711717
712718 auto pendingV = llvm::ConstantInt::get (
713719 contAwaitSyncAddr->getType ()->getPointerElementType (),
@@ -759,11 +765,11 @@ void IRGenFunction::emitAwaitAsyncContinuation(
759765 Builder.CreateBitOrPointerCast (awaitFnPtr, IGM.Int8PtrTy ));
760766
761767 if (useContinuationAwait) {
762- arguments.push_back (AsyncCoroutineCurrentContinuationContext );
768+ arguments.push_back (continuationContext. getAddress () );
763769 } else {
764770 arguments.push_back (AsyncCoroutineCurrentResume);
765771 arguments.push_back (Builder.CreateBitOrPointerCast (
766- AsyncCoroutineCurrentContinuationContext , IGM.Int8PtrTy ));
772+ continuationContext. getAddress () , IGM.Int8PtrTy ));
767773 }
768774
769775 auto resultTy =
@@ -777,12 +783,7 @@ void IRGenFunction::emitAwaitAsyncContinuation(
777783 if (optionalErrorBB) {
778784 auto normalContBB = createBasicBlock (" await.async.normal" );
779785 auto contErrResultAddr =
780- Address (Builder.CreateStructGEP (
781- AsyncCoroutineCurrentContinuationContext->getType ()
782- ->getScalarType ()
783- ->getPointerElementType (),
784- AsyncCoroutineCurrentContinuationContext, 2 ),
785- pointerAlignment);
786+ emitAddrOfContinuationErrorResultPointer (*this , continuationContext);
786787 auto errorRes = Builder.CreateLoad (contErrResultAddr);
787788 auto nullError = llvm::Constant::getNullValue (errorRes->getType ());
788789 auto hasError = Builder.CreateICmpNE (errorRes, nullError);
@@ -795,13 +796,10 @@ void IRGenFunction::emitAwaitAsyncContinuation(
795796 // result slot, load from the temporary we created during
796797 // get_async_continuation.
797798 if (!isIndirectResult) {
798- auto contResultAddrAddr = Builder.CreateStructGEP (
799- AsyncCoroutineCurrentContinuationContext->getType ()
800- ->getScalarType ()
801- ->getPointerElementType (),
802- AsyncCoroutineCurrentContinuationContext, 3 );
799+ auto contResultAddrAddr =
800+ emitAddrOfContinuationNormalResultPointer (*this , continuationContext);
803801 auto resultAddrVal =
804- Builder.CreateLoad (Address ( contResultAddrAddr, pointerAlignment) );
802+ Builder.CreateLoad (contResultAddrAddr);
805803 // Take the result.
806804 auto &resumeTI = cast<LoadableTypeInfo>(getTypeInfo (resumeTy));
807805 auto resultStorageTy = resumeTI.getStorageType ();
0 commit comments