Skip to content

Commit 209a7a2

Browse files
authored
Merge pull request #81878 from jckarter/addressable-scope-for-captures
SILGen: Establish an addressability scope for closure captures.
2 parents d49dd18 + 9904d6c commit 209a7a2

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,6 +2542,8 @@ SILGenFunction::getLocalVariableAddressableBuffer(VarDecl *decl,
25422542
SILValue reabstraction, allocStack, storeBorrow;
25432543
{
25442544
SavedInsertionPointRAII save(B);
2545+
ASSERT(AddressableBuffers.find(decl) != AddressableBuffers.end()
2546+
&& "local variable did not have an addressability scope set");
25452547
auto insertPoint = AddressableBuffers[decl].insertPoint;
25462548
B.setInsertionPoint(insertPoint);
25472549
auto allocStackTy = fullyAbstractedTy;

lib/SILGen/SILGenFunction.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
543543

544544
PreparedAddressableBuffer(SILInstruction *insertPoint)
545545
: insertPoint(insertPoint)
546-
{}
546+
{
547+
ASSERT(insertPoint && "null insertion point provided");
548+
}
547549

548550
PreparedAddressableBuffer(PreparedAddressableBuffer &&other)
549551
: insertPoint(other.insertPoint)

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,7 @@ static void emitCaptureArguments(SILGenFunction &SGF,
14061406
}
14071407

14081408
SGF.VarLocs[VD] = SILGenFunction::VarLoc(arg, enforcement, box);
1409+
SGF.enterLocalVariableAddressableBufferScope(VD);
14091410
SILDebugVariable DbgVar(VD->isLet(), ArgNo);
14101411
if (auto *AllocStack = dyn_cast<AllocStackInst>(arg)) {
14111412
AllocStack->setArgNo(ArgNo);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-emit-silgen -verify -enable-experimental-feature LifetimeDependence -enable-experimental-feature AddressableTypes %s
2+
3+
// REQUIRES: swift_feature_LifetimeDependence
4+
// REQUIRES: swift_feature_AddressableTypes
5+
6+
@_addressableForDependencies
7+
struct Owner {
8+
@lifetime(borrow self)
9+
func reference() -> Reference { fatalError() }
10+
}
11+
12+
struct Reference: ~Escapable {
13+
@lifetime(immortal)
14+
init() { fatalError() }
15+
16+
func use() {}
17+
}
18+
19+
func closure(_: () -> Void) {}
20+
21+
func dependencyThroughClosure(from owner: borrowing Owner) {
22+
closure { owner.reference().use() }
23+
}

0 commit comments

Comments
 (0)