@@ -174,7 +174,12 @@ Alignment IRGenModule::getAsyncContextAlignment() const {
174174void IRGenFunction::setupAsync (unsigned asyncContextIndex) {
175175 llvm::Value *c = CurFn->getArg (asyncContextIndex);
176176 asyncContextLocation = createAlloca (c->getType (), IGM.getPointerAlignment ());
177- Builder.CreateStore (c, asyncContextLocation);
177+
178+ IRBuilder builder (IGM.getLLVMContext (), IGM.DebugInfo != nullptr );
179+ // Insert the stores after the coro.begin.
180+ builder.SetInsertPoint (getEarliestInsertionPoint ()->getParent (),
181+ getEarliestInsertionPoint ()->getIterator ());
182+ builder.CreateStore (c, asyncContextLocation);
178183}
179184
180185llvm::Value *IRGenFunction::getAsyncTask () {
@@ -3771,6 +3776,11 @@ emitRetconCoroutineEntry(IRGenFunction &IGF, CanSILFunctionType fnType,
37713776 // Set the coroutine handle; this also flags that is a coroutine so that
37723777 // e.g. dynamic allocas use the right code generation.
37733778 IGF.setCoroutineHandle (hdl);
3779+
3780+ auto *pt = IGF.Builder .IRBuilderBase ::CreateAlloca (IGF.IGM .Int1Ty ,
3781+ /* array size*/ nullptr ,
3782+ " earliest insert point" );
3783+ IGF.setEarliestInsertionPoint (pt);
37743784}
37753785
37763786void irgen::emitAsyncFunctionEntry (IRGenFunction &IGF,
@@ -3796,6 +3806,11 @@ void irgen::emitAsyncFunctionEntry(IRGenFunction &IGF,
37963806 // Set the coroutine handle; this also flags that is a coroutine so that
37973807 // e.g. dynamic allocas use the right code generation.
37983808 IGF.setCoroutineHandle (hdl);
3809+ auto *pt = IGF.Builder .IRBuilderBase ::CreateAlloca (IGF.IGM .Int1Ty ,
3810+ /* array size*/ nullptr ,
3811+ " earliest insert point" );
3812+ IGF.setEarliestInsertionPoint (pt);
3813+ IGF.setupAsync (asyncContextIndex);
37993814}
38003815
38013816void irgen::emitYieldOnceCoroutineEntry (
@@ -4054,6 +4069,11 @@ Address IRGenFunction::createErrorResultSlot(SILType errorType, bool isAsync) {
40544069 auto addr = createAlloca (errorTI.getStorageType (),
40554070 errorTI.getFixedAlignment (), " swifterror" );
40564071
4072+ if (!isAsync) {
4073+ builder.SetInsertPoint (getEarliestInsertionPoint ()->getParent (),
4074+ getEarliestInsertionPoint ()->getIterator ());
4075+ }
4076+
40574077 // Only add the swifterror attribute on ABIs that pass it in a register.
40584078 // We create a shadow stack location of the swifterror parameter for the
40594079 // debugger on platforms that pass swifterror by reference and so we can't
@@ -4131,6 +4151,7 @@ void IRGenFunction::emitPrologue() {
41314151 AllocaIP = Builder.IRBuilderBase ::CreateAlloca (IGM.Int1Ty ,
41324152 /* array size*/ nullptr ,
41334153 " alloca point" );
4154+ EarliestIP = AllocaIP;
41344155}
41354156
41364157// / Emit a branch to the return block and set the insert point there.
@@ -4170,6 +4191,8 @@ bool IRGenFunction::emitBranchToReturnBB() {
41704191
41714192// / Emit the epilogue for the function.
41724193void IRGenFunction::emitEpilogue () {
4194+ if (EarliestIP != AllocaIP)
4195+ EarliestIP->eraseFromParent ();
41734196 // Destroy the alloca insertion point.
41744197 AllocaIP->eraseFromParent ();
41754198}
0 commit comments