Skip to content

Commit 01c3343

Browse files
committed
Fix mark_dependence ownership: compatibility with owned values
This fixes an OSSA verification bug introduced here: commit 79b6498 Author: Meghana Gupta <[email protected]> Date: Wed Jan 22 01:24:49 2025 Fix operand ownership of mark_dependence [nonescaping] of address values The bug only showed up with mark_dependence [nonescaping], which means mainly affects `~Escapable` types. Adddressors happened to work because SILGen was emitting a borrow scope around them. Rather than reverting the change above, this fix migrates mark_dependence [nonescaping] to an implicit borrow scope. Fixes rdar://144199759 (Assert: mark_dependence [nonescaping]: ownership incompatible with an owned value)
1 parent e705a6d commit 01c3343

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ OperandOwnershipClassifier::visitMarkDependenceInst(MarkDependenceInst *mdi) {
678678
// which we treat like a borrow.
679679
return OperandOwnership::Borrow;
680680
}
681-
return OperandOwnership::InteriorPointer;
681+
return OperandOwnership::AnyInteriorPointer;
682682
}
683683
if (mdi->hasUnresolvedEscape()) {
684684
// This creates a dependent value that may extend beyond the parent's

lib/SIL/IR/SILInstruction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,7 @@ bool MarkDependenceInst::visitNonEscapingLifetimeEnds(
20092009
llvm::function_ref<bool (Operand *)> visitUnknownUse) const {
20102010
assert(getFunction()->hasOwnership() && isNonEscaping()
20112011
&& "only meaningful for nonescaping dependencies");
2012+
assert(getType().isObject() && "lifetime ends only exist for values");
20122013
bool noUsers = true;
20132014
if (!visitRecursivelyLifetimeEndingUses(this, noUsers, visitScopeEnd,
20142015
visitUnknownUse)) {

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ bool BorrowingOperand::visitScopeEndingUses(
715715
case BorrowingOperandKind::MarkDependenceNonEscaping: {
716716
auto *user = cast<MarkDependenceInst>(op->getUser());
717717
assert(user->isNonEscaping() && "escaping dependencies don't borrow");
718+
assert(user->getType().isObject() && "borrows only exist for values");
718719
return user->visitNonEscapingLifetimeEnds(visitScopeEnd, visitUnknownUse);
719720
}
720721
case BorrowingOperandKind::BeginAsyncLet: {

test/SILOptimizer/ossa_lifetime_completion.sil

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ struct Wrapper {
965965

966966
// CHECK-LABEL: begin running test {{.*}} on testInteriorMarkDepNonEscAddressValue: ossa_lifetime_completion
967967
// CHECK-LABEL: sil [ossa] @testInteriorMarkDepNonEscAddressValue : {{.*}} {
968-
// CHECK: mark_dependence
968+
// CHECK: mark_dependence [nonescaping]
969969
// CHECK: end_borrow
970970
// CHECK-LABEL: } // end sil function 'testInteriorMarkDepNonEscAddressValue'
971971
// CHECK-LABEL: end running test {{.*}} on testInteriorMarkDepNonEscAddressValue: ossa_lifetime_completion
@@ -978,5 +978,18 @@ bb0(%0 : @owned $Wrapper, %1 : $*Klass):
978978
unreachable
979979
}
980980

981+
// CHECK-LABEL: begin running test {{.*}} on testOwnedMarkDepNonEscAddressValue: ossa_lifetime_completion
982+
// CHECK-LABEL: sil [ossa] @testOwnedMarkDepNonEscAddressValue : {{.*}} {
983+
// CHECK: end_borrow
984+
// CHECK: mark_dependence [nonescaping]
985+
// CHECK: destroy_value [dead_end] %0
986+
// CHECK-LABEL: } // end sil function 'testOwnedMarkDepNonEscAddressValue'
987+
// CHECK-LABEL: end running test {{.*}} on testOwnedMarkDepNonEscAddressValue: ossa_lifetime_completion
988+
sil [ossa] @testOwnedMarkDepNonEscAddressValue : $@convention(thin) (@owned Wrapper, @inout Klass) -> () {
989+
bb0(%0 : @owned $Wrapper, %1 : $*Klass):
990+
specify_test "ossa_lifetime_completion %0 liveness"
991+
%2 = begin_borrow %0 : $Wrapper
992+
%3 = struct_extract %2 : $Wrapper, #Wrapper.c
993+
%4 = mark_dependence [nonescaping] %1 : $*Klass on %0 : $Wrapper
981994
unreachable
982995
}

0 commit comments

Comments
 (0)