Skip to content

Commit 42f339f

Browse files
authored
Fix ownership verifier to handle is_unique as a valid use of interior pointer op (swiftlang#38838)
1 parent ee91879 commit 42f339f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ bool InteriorPointerOperand::findTransitiveUsesForAddress(
718718
isa<AssignByWrapperInst>(user) || isa<BeginUnpairedAccessInst>(user) ||
719719
isa<EndUnpairedAccessInst>(user) || isa<WitnessMethodInst>(user) ||
720720
isa<SwitchEnumAddrInst>(user) || isa<CheckedCastAddrBranchInst>(user) ||
721-
isa<SelectEnumAddrInst>(user) || isa<InjectEnumAddrInst>(user)) {
721+
isa<SelectEnumAddrInst>(user) || isa<InjectEnumAddrInst>(user) ||
722+
isa<IsUniqueInst>(user)) {
722723
continue;
723724
}
724725

test/SIL/ownership-verifier/interior_pointer.sil

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ bb0(%0 : @owned $Box<T>, %1 : $*Int):
103103
return %4 : $()
104104
}
105105

106+
// CHECK-NOT: Function: 'isunique_test'
107+
sil [ossa] @isunique_test : $@convention(thin) <T> (@owned Box<T>, @in Int) -> () {
108+
bb0(%0 : @owned $Box<T>, %1 : $*Int):
109+
%2 = begin_borrow %0 : $Box<T>
110+
%3 = ref_element_addr %2 : $Box<T>, #Box.t
111+
%4 = is_unique %3 : $*T
112+
end_borrow %2 : $Box<T>
113+
destroy_value %0 : $Box<T>
114+
%5 = tuple ()
115+
return %5 : $()
116+
}
117+
106118
// CHECK-LABEL: Error#: 0. Begin Error in Function: 'store_borrow_result_used_outside_of_borrow_lifetime'
107119
// CHECK-NEXT: Found outside of lifetime use?!
108120
// CHECK-NEXT: Value: %1 = begin_borrow %0 : $Builtin.NativeObject // users: %4, %3

0 commit comments

Comments
 (0)