Skip to content

Commit 736a848

Browse files
authored
Merge pull request swiftlang#32143 from gottesmm/pr-18735e23f15ef6aaa8992016e9c6ac89c2102eb4
[ownership] Add support for handling address_to_pointer to LoadBorrowInvalidationChecker.
2 parents 7498464 + 58e49db commit 736a848

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/SIL/Verifier/LoadBorrowInvalidationChecker.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ constructValuesForKey(SILValue initialValue,
247247
continue;
248248
}
249249

250+
// We consider address_to_pointer to be an escape from our system. The
251+
// frontend must protect the uses of the load_borrow as appropriate in other
252+
// ways (for instance by using a mark_dependence).
253+
if (isa<AddressToPointerInst>(user)) {
254+
continue;
255+
}
256+
250257
if (auto *yi = dyn_cast<YieldInst>(user)) {
251258
auto info = yi->getYieldInfoForOperand(*op);
252259
if (info.isIndirectInGuaranteed()) {

test/SIL/ownership-verifier/load_borrow_invalidation_test.sil

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import Builtin
88
// patterns look next door for verifier error checks.
99

1010
sil @inoutCallee : $@convention(thin) (@inout Builtin.NativeObject) -> ()
11+
sil @guaranteedUser : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
12+
sil @useRawPointer : $@convention(thin) (Builtin.RawPointer) -> ()
1113

1214
//////////////////////////
1315
// InOut Argument Tests //
@@ -375,3 +377,21 @@ bb3:
375377
%9999 = tuple()
376378
return %9999 : $()
377379
}
380+
381+
sil [ossa] @pointer_to_address_is_assumed_to_be_safe : $@convention(thin) (@owned Builtin.NativeObject) -> () {
382+
bb0(%0 : @owned $Builtin.NativeObject):
383+
%1 = alloc_stack $Builtin.NativeObject
384+
store %0 to [init] %1 : $*Builtin.NativeObject
385+
%2 = load_borrow %1 : $*Builtin.NativeObject
386+
%gUser = function_ref @guaranteedUser : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
387+
apply %gUser(%2) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
388+
end_borrow %2 : $Builtin.NativeObject
389+
%3 = address_to_pointer %1 : $*Builtin.NativeObject to $Builtin.RawPointer
390+
%4 = mark_dependence %3 : $Builtin.RawPointer on %1 : $*Builtin.NativeObject
391+
%rawPointerUser = function_ref @useRawPointer : $@convention(thin) (Builtin.RawPointer) -> ()
392+
apply %rawPointerUser(%4) : $@convention(thin) (Builtin.RawPointer) -> ()
393+
destroy_addr %1 : $*Builtin.NativeObject
394+
dealloc_stack %1 : $*Builtin.NativeObject
395+
%9999 = tuple()
396+
return %9999 : $()
397+
}

0 commit comments

Comments
 (0)