Skip to content

Commit 60a62db

Browse files
Merge pull request #72556 from nate-chandler/lifetime-completion/20240325/1
[LifetimeCompletion] Handle project_box.
2 parents c256c1f + 57eb1db commit 60a62db

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

include/swift/SIL/OwnershipUseVisitor.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ bool OwnershipUseVisitor<Impl>::visitGuaranteedUse(Operand *use) {
391391
return true;
392392

393393
case OperandOwnership::PointerEscape:
394+
// TODO: Change ProjectBox ownership to InteriorPointer and allow them to
395+
// take owned values.
396+
if (isa<ProjectBoxInst>(use->getUser())) {
397+
return visitInteriorPointerUses(use);
398+
}
394399
if (!asImpl().handlePointerEscape(use))
395400
return false;
396401

@@ -443,7 +448,8 @@ bool OwnershipUseVisitor<Impl>::visitGuaranteedUse(Operand *use) {
443448

444449
template <typename Impl>
445450
bool OwnershipUseVisitor<Impl>::visitInteriorPointerUses(Operand *use) {
446-
assert(use->getOperandOwnership() == OperandOwnership::InteriorPointer);
451+
assert(use->getOperandOwnership() == OperandOwnership::InteriorPointer ||
452+
isa<ProjectBoxInst>(use->getUser()));
447453

448454
if (auto scopedAddress = ScopedAddressValue::forUse(use)) {
449455
// e.g. client may need to insert end_borrow if scopedAddress is a store_borrow.

test/SILOptimizer/ossa_lifetime_completion.sil

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ exit:
266266
}
267267

268268
// CHECK-LABEL: sil [ossa] @availability_boundary_2_after_loop : {{.*}} {
269-
// CHECK: [[REGISTER_1:%[^,]+]] = move_value [lexical]
269+
// CHECK: [[LEXICAL:%[^,]+]] = move_value [lexical]
270270
// CHECK: br [[CONDITION_1:bb[0-9]+]]
271271
// CHECK: [[CONDITION_1]]:
272272
// CHECK: cond_br undef, [[CONDITION_2:bb[0-9]+]], [[PREHEADER:bb[0-9]+]]
273273
// CHECK: [[CONDITION_2]]:
274-
// CHECK: destroy_value [[REGISTER_1]]
274+
// CHECK: destroy_value [[LEXICAL]]
275275
// CHECK: cond_br undef, [[EXIT:bb[0-9]+]], [[TO_DIE_2:bb[0-9]+]]
276276
// CHECK: [[PREHEADER]]:
277277
// CHECK: br [[HEADER:bb[0-9]+]]
@@ -282,7 +282,7 @@ exit:
282282
// CHECK: [[BACKEDGE]]:
283283
// CHECK: br [[HEADER]]
284284
// CHECK: [[TO_DIE_1]]:
285-
// CHECK: destroy_value [[REGISTER_1]]
285+
// CHECK: destroy_value [[LEXICAL]]
286286
// CHECK: br [[DIE:bb[0-9]+]]
287287
// CHECK: [[TO_DIE_2]]:
288288
// CHECK: br [[DIE]]
@@ -395,3 +395,22 @@ exit:
395395
%retval = tuple ()
396396
return %retval : $()
397397
}
398+
399+
// CHECK-LABEL: sil [ossa] @project_box_deadend : {{.*}} {
400+
// CHECK: bb0([[C:%[^,]+]] :
401+
// CHECK: [[BOX:%[^,]+]] = alloc_box
402+
// CHECK: [[BOX_BORROW:%[^,]+]] = begin_borrow [[BOX]]
403+
// CHECK: [[ADDR:%[^,]+]] = project_box [[BOX_BORROW]]
404+
// CHECK: store [[C]] to [init] [[ADDR]]
405+
// CHECK: end_borrow [[BOX_BORROW]]
406+
// CHECK: unreachable
407+
// CHECK-LABEL: } // end sil function 'project_box_deadend'
408+
sil [ossa] @project_box_deadend : $@convention(thin) (@owned C) -> () {
409+
bb0(%0 : @owned $C):
410+
%2 = alloc_box ${ var C }
411+
%3 = begin_borrow %2 : ${ var C }
412+
specify_test "ossa-lifetime-completion %3"
413+
%4 = project_box %3 : ${ var C }, 0
414+
store %0 to [init] %4 : $*C
415+
unreachable
416+
}

0 commit comments

Comments
 (0)