Skip to content

Commit db90ea2

Browse files
authored
Fix the ownership kind of success bb arg when emitting checked_cast_br` (swiftlang#39347)
1 parent e159c0f commit db90ea2

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lib/SIL/Utils/DynamicCasts.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,14 +1288,14 @@ void swift::emitIndirectConditionalCastWithScalar(
12881288
return B.emitLoadValueOperation(loc, srcAddr, LoadOwnershipQualifier::Take);
12891289
})();
12901290

1291-
B.createCheckedCastBranch(loc, /*exact*/ false, srcValue, targetLoweredType,
1292-
targetFormalType, scalarSuccBB, scalarFailBB,
1293-
TrueCount, FalseCount);
1291+
auto *ccb = B.createCheckedCastBranch(
1292+
loc, /*exact*/ false, srcValue, targetLoweredType, targetFormalType,
1293+
scalarSuccBB, scalarFailBB, TrueCount, FalseCount);
12941294

12951295
// Emit the success block.
12961296
B.setInsertionPoint(scalarSuccBB); {
12971297
SILValue succValue = scalarSuccBB->createPhiArgument(
1298-
targetLoweredType, srcValue.getOwnershipKind());
1298+
targetLoweredType, ccb->getForwardingOwnershipKind());
12991299

13001300
switch (consumption) {
13011301
// On success, we take with both take_always and take_on_success.

test/SILOptimizer/mandatory_inlining_ownership.sil

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ private class C2 {
1717

1818
class Klass {}
1919

20+
class AnotherKlass {}
21+
2022
sil [transparent] [ossa] @calleeWithGuaranteed : $@convention(thin) (@guaranteed C) -> Builtin.Int64 {
2123
bb(%0 : @guaranteed $C):
2224
%1 = ref_element_addr %0 : $C, #C.i
@@ -270,6 +272,23 @@ bb3:
270272
return %9999 : $()
271273
}
272274

275+
sil [transparent] [ossa] @term_ossa_checked_cast_addr_br_takealways_callee2 : $@convention(thin) (@in @thick Klass.Type) -> () {
276+
bb0(%0 : $*@thick Klass.Type):
277+
%2 = alloc_stack $AnotherKlass
278+
checked_cast_addr_br take_always Klass in %0 : $*@thick Klass.Type to Klass in %2 : $*AnotherKlass, bb1, bb2
279+
280+
bb1:
281+
destroy_addr %2 : $*AnotherKlass
282+
br bb3
283+
284+
bb2:
285+
br bb3
286+
287+
bb3:
288+
dealloc_stack %2 : $*AnotherKlass
289+
%9999 = tuple()
290+
return %9999 : $()
291+
}
273292

274293
// CHECK-LABEL: sil [ossa] @term_nonossa_checked_cast_addr_br_takealways_caller : $@convention(thin) (@owned Builtin.NativeObject) -> () {
275294
// CHECK: bb0([[ARG:%.*]] :
@@ -305,6 +324,25 @@ bb0(%0 : @owned $Builtin.NativeObject):
305324
return %9999 : $()
306325
}
307326

327+
sil [ossa] @get_klass_type : $@convention(thin) () -> @out @thick Klass.Type
328+
329+
// CHECK-LABEL: sil [ossa] @term_nonossa_checked_cast_addr_br_takealways_caller2 :
330+
// CHECK: checked_cast_br {{.*}} : $@thick Klass.Type to Klass, [[SUCCESS_BB:bb[0-9]+]], [[FAILURE_BB:bb[0-9]+]], forwarding: @owned
331+
// CHECK: [[SUCCESS_BB]]({{.*}}@owned $AnotherKlass):
332+
// CHECK: [[FAILURE_BB]]([[FAILURE_ARG:%.*]] :
333+
// CHECK: } // end sil function 'term_nonossa_checked_cast_addr_br_takealways_caller2'
334+
sil [ossa] @term_nonossa_checked_cast_addr_br_takealways_caller2 : $@convention(thin) () -> () {
335+
bb0:
336+
%res = alloc_stack $@thick Klass.Type
337+
%2 = function_ref @get_klass_type : $@convention(thin) () -> @out @thick Klass.Type
338+
apply %2(%res) : $@convention(thin) () -> @out @thick Klass.Type
339+
%3 = function_ref @term_ossa_checked_cast_addr_br_takealways_callee2 : $@convention(thin) (@in @thick Klass.Type) -> ()
340+
apply %3(%res) : $@convention(thin) (@in @thick Klass.Type) -> ()
341+
dealloc_stack %res : $*@thick Klass.Type
342+
%9999 = tuple()
343+
return %9999 : $()
344+
}
345+
308346
sil [transparent] [ossa] @term_ossa_checked_cast_addr_br_takeonsuccess_callee : $@convention(thin) (@owned Builtin.NativeObject) -> () {
309347
bb0(%0 : @owned $Builtin.NativeObject):
310348
%1 = alloc_stack $Builtin.NativeObject

0 commit comments

Comments
 (0)