Skip to content

Commit fbd08c6

Browse files
committed
[SIL] Preserve pointer_escape flag during cloning.
1 parent 26b91ef commit fbd08c6

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,9 +1218,9 @@ void SILCloner<ImplClass>::visitBeginBorrowInst(BeginBorrowInst *Inst) {
12181218
}
12191219

12201220
recordClonedInstruction(
1221-
Inst, getBuilder().createBeginBorrow(getOpLocation(Inst->getLoc()),
1222-
getOpValue(Inst->getOperand()),
1223-
Inst->isLexical()));
1221+
Inst, getBuilder().createBeginBorrow(
1222+
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
1223+
Inst->isLexical(), Inst->hasPointerEscape()));
12241224
}
12251225

12261226
template <typename ImplClass>
@@ -1930,9 +1930,9 @@ void SILCloner<ImplClass>::visitMoveValueInst(MoveValueInst *Inst) {
19301930
if (!getBuilder().hasOwnership()) {
19311931
return recordFoldedValue(Inst, getOpValue(Inst->getOperand()));
19321932
}
1933-
auto *MVI = getBuilder().createMoveValue(getOpLocation(Inst->getLoc()),
1934-
getOpValue(Inst->getOperand()),
1935-
Inst->isLexical());
1933+
auto *MVI = getBuilder().createMoveValue(
1934+
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
1935+
Inst->isLexical(), Inst->hasPointerEscape());
19361936
MVI->setAllowsDiagnostics(Inst->getAllowDiagnostics());
19371937
recordClonedInstruction(Inst, MVI);
19381938
}

test/SIL/cloning.sil

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@ bb0:
2828
return %2 : $()
2929
}
3030

31-
sil [ossa] [always_inline] @callee_begin_borrow_lexical : $@convention(thin) () -> () {
31+
sil [ossa] [always_inline] @callee_begin_borrow : $@convention(thin) () -> () {
3232
%instance = alloc_ref $X
3333
%guaranteed_c = begin_borrow [lexical] %instance : $X
3434
end_borrow %guaranteed_c : $X
35+
%guaranteed_c2 = begin_borrow [pointer_escape] %instance : $X
36+
end_borrow %guaranteed_c2 : $X
3537
destroy_value %instance : $X
3638
%res = tuple ()
3739
return %res : $()
3840
}
3941

4042
// CHECK-LABEL: sil [ossa] @caller_begin_borrow_lexical
4143
// CHECK: begin_borrow [lexical]
44+
// CHECK: begin_borrow [pointer_escape]
4245
// CHECK-LABEL: } // end sil function 'caller_begin_borrow_lexical'
4346
sil [ossa] @caller_begin_borrow_lexical : $@convention(thin) () -> () {
44-
%callee_begin_borrow_lexical = function_ref @callee_begin_borrow_lexical : $@convention(thin) () -> ()
47+
%callee_begin_borrow_lexical = function_ref @callee_begin_borrow : $@convention(thin) () -> ()
4548
%res = apply %callee_begin_borrow_lexical() : $@convention(thin) () -> ()
4649
return %res : $()
4750
}
@@ -77,7 +80,8 @@ entry(%0 : @owned $Builtin.NativeObject):
7780
%2 = move_value [allows_diagnostics] %1 : $Builtin.NativeObject
7881
%3 = move_value [lexical] %2 : $Builtin.NativeObject
7982
%4 = move_value [allows_diagnostics] [lexical] %3 : $Builtin.NativeObject
80-
return %4 : $Builtin.NativeObject
83+
%5 = move_value [pointer_escape] %4 : $Builtin.NativeObject
84+
return %5 : $Builtin.NativeObject
8185
}
8286

8387
// CHECK-LABEL: sil [ossa] @caller_move_value {{.*}} {
@@ -86,7 +90,8 @@ entry(%0 : @owned $Builtin.NativeObject):
8690
// CHECK: [[REGISTER_2:%[^,]+]] = move_value [allows_diagnostics] [[REGISTER_1]]
8791
// CHECK: [[REGISTER_3:%[^,]+]] = move_value [lexical] [[REGISTER_2]]
8892
// CHECK: [[REGISTER_4:%[^,]+]] = move_value [allows_diagnostics] [lexical] [[REGISTER_3]]
89-
// CHECK: return [[REGISTER_4]]
93+
// CHECK: [[REGISTER_5:%[^,]+]] = move_value [pointer_escape] [[REGISTER_4]]
94+
// CHECK: return [[REGISTER_5]]
9095
// CHECK-LABEL: } // end sil function 'caller_move_value'
9196
sil [ossa] @caller_move_value : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject {
9297
entry(%0 : @owned $Builtin.NativeObject):

0 commit comments

Comments
 (0)