File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -969,7 +969,14 @@ BeginBorrowInst *OwnershipLifetimeExtender::borrowCopyOverGuaranteedUsers(
969
969
// Create destroys at the end of copy's lifetime. This only needs to consider
970
970
// uses that end the borrow scope.
971
971
{
972
- ValueLifetimeAnalysis lifetimeAnalysis (copy, borrow->getEndBorrows ());
972
+ SmallVector<SILInstruction *, 16 > users;
973
+ for (auto *user : guaranteedUsers) {
974
+ users.push_back (user);
975
+ }
976
+ for (auto *user : borrow->getEndBorrows ()) {
977
+ users.push_back (user);
978
+ }
979
+ ValueLifetimeAnalysis lifetimeAnalysis (copy, users);
973
980
ValueLifetimeBoundary copyBoundary;
974
981
lifetimeAnalysis.computeLifetimeBoundary (copyBoundary);
975
982
Original file line number Diff line number Diff line change @@ -1164,3 +1164,38 @@ bb0:
1164
1164
%13 = tuple ()
1165
1165
return %13
1166
1166
}
1167
+
1168
+ /// A scenario where a borrow of a copy is introduced but the cfg is such that
1169
+ /// no end_borrows are inserted for the borrow. The copy must still be
1170
+ /// destroyed.
1171
+ // CHECK-LABEL: sil [ossa] @no_boundary_for_end_borrows : {{.*}} {
1172
+ // TODO: There shouldn't actually be a copy_value here, but lifetime transfer
1173
+ // APIs are written and OSSARAUWHelper is in use, there will be.
1174
+ // Even then, this test case shouldn't crash.
1175
+ // CHECK: copy_value
1176
+ // CHECK: destroy_value
1177
+ // CHECK-LABEL: } // end sil function 'no_boundary_for_end_borrows'
1178
+ sil [ossa] @no_boundary_for_end_borrows : $@convention(thin) (@guaranteed NonTrivialStruct) -> () {
1179
+ entry(%s : @guaranteed $NonTrivialStruct):
1180
+ %c1 = struct_extract %s : $NonTrivialStruct, #NonTrivialStruct.val
1181
+ cond_br undef, loop_entry, exit
1182
+
1183
+ exit:
1184
+ apply undef(%c1) : $@convention(thin) (@guaranteed Klass) -> ()
1185
+ return undef : $()
1186
+
1187
+ loop_entry:
1188
+ %c2 = struct_extract %s : $NonTrivialStruct, #NonTrivialStruct.val
1189
+ apply undef(%c2) : $@convention(thin) (@guaranteed Klass) -> ()
1190
+ br loop_header
1191
+
1192
+ loop_header:
1193
+ apply undef(%c2) : $@convention(thin) (@guaranteed Klass) -> ()
1194
+ cond_br undef, die, loop_backedge
1195
+
1196
+ loop_backedge:
1197
+ br loop_header
1198
+
1199
+ die:
1200
+ unreachable
1201
+ }
You can’t perform that action at this time.
0 commit comments