Skip to content

Commit 3d779cd

Browse files
committed
IRGen: Fix DenseMap interior pointer invalidation bug in IRGenSILFunction::visitEndApply.
Fixes rdar://144216380.
1 parent 4937d0a commit 3d779cd

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4787,20 +4787,25 @@ void IRGenSILFunction::visitEndApply(BeginApplyInst *i, EndApplyInst *ei) {
47874787
llvm::ConstantInt::get(IGM.Int1Ty, isAbort)
47884788
});
47894789

4790+
// Destroy the temporaries before setting the lowered value for `ei`, since
4791+
// `setLoweredExplosion` will insert into the LoweredValues DenseMap and
4792+
// invalidate the `coroutine` reference.
4793+
coroutine.Temporaries.destroyAll(*this);
4794+
emitDeallocYieldOnceCoroutineBuffer(*this, coroutine.Buffer);
4795+
47904796
if (!isAbort) {
47914797
auto resultType = call->getType();
47924798
if (!resultType->isVoidTy()) {
47934799
Explosion e;
47944800
// FIXME: Do we need to handle ABI-related conversions here?
47954801
// It seems we cannot have C function convention for coroutines, etc.
47964802
extractScalarResults(*this, resultType, call, e);
4803+
4804+
// NOTE: This inserts a new entry into the LoweredValues DenseMap,
4805+
// invalidating the reference held by `coroutine`.
47974806
setLoweredExplosion(ei, e);
47984807
}
47994808
}
4800-
4801-
coroutine.Temporaries.destroyAll(*this);
4802-
4803-
emitDeallocYieldOnceCoroutineBuffer(*this, coroutine.Buffer);
48044809
}
48054810

48064811
static llvm::BasicBlock *emitBBMapForSwitchValue(

test/AutoDiff/validation-test/modify_accessor.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// REQUIRES: rdar144216380
2-
31
// RUN: %target-run-simple-swift
42
// REQUIRES: executable_test
53

0 commit comments

Comments
 (0)