@@ -9,6 +9,7 @@ sil_stage canonical
9
9
import Builtin
10
10
import Swift
11
11
12
+ sil [ossa] @getOwnedC : $@convention(thin) () -> (@owned C)
12
13
sil [ossa] @takeOwned : $@convention(thin) <T> (@in T) -> ()
13
14
sil [ossa] @takeMultipleOwned : $@convention(thin) <T> (@in T, @in T) -> ()
14
15
sil [ossa] @takeGuaranteed : $@convention(thin) <T> (@in_guaranteed T) -> ()
@@ -1458,17 +1459,18 @@ bb3:
1458
1459
// with cross-block reborrows. Its lifetime must be extended past the
1459
1460
// end_borrow of the phi.
1460
1461
//
1462
+ // TODO: CanonicalizeOSSA currently bails out on reborrows.
1463
+ //
1461
1464
// CHECK-LABEL: sil [ossa] @testSubReborrowExtension : $@convention(thin) () -> () {
1462
1465
// CHECK: bb0:
1463
- // CHECK: [[ALLOC:%.*]] = alloc_ref $C
1464
- // CHECK: [[BORROW:%.*]] = begin_borrow %0 : $C
1466
+ // CHECK: [[ALLOC:%.*]] = alloc_ref $C
1467
+ // CHECK: [[CP:%.*]] = copy_value %0 : $C
1468
+ // CHECK: [[BORROW:%.*]] = begin_borrow %0 : $C
1465
1469
// CHECK: cond_br undef, bb1, bb2
1466
1470
// CHECK: bb1:
1467
- // CHECK: [[CP1:%.*]] = copy_value %0 : $C
1468
- // CHECK: br bb3([[CP1]] : $C, [[BORROW]] : $C)
1471
+ // CHECK: br bb3([[CP]] : $C, [[BORROW]] : $C)
1469
1472
// CHECK: bb2:
1470
- // CHECK: [[CP2:%.*]] = copy_value %0 : $C
1471
- // CHECK: br bb3([[CP2]] : $C, [[BORROW]] : $C)
1473
+ // CHECK: br bb3([[CP]] : $C, [[BORROW]] : $C)
1472
1474
// CHECK: bb3([[OWNEDPHI:%.*]] : @owned $C, [[BORROWPHI:%.*]] @guaranteed $C
1473
1475
// CHECK: end_borrow [[BORROWPHI]]
1474
1476
// CHECK: destroy_value [[OWNEDPHI]] : $C
@@ -1628,3 +1630,42 @@ bb3(%borrowphi : @guaranteed $C):
1628
1630
%99 = tuple ()
1629
1631
return %99 : $()
1630
1632
}
1633
+
1634
+ // Test a reborrow of an owned-and-copied def that does not dominate
1635
+ // the extended borrow scope.
1636
+ //
1637
+ // CHECK-LABEL: sil [ossa] @testOwnedReborrow : $@convention(thin) (@owned C) -> () {
1638
+ // CHECK: bb1:
1639
+ // CHECK: destroy_value %0 : $C
1640
+ // CHECK: [[CALL:%.*]] = apply %{{.*}}() : $@convention(thin) () -> @owned C
1641
+ // CHECK: [[COPY1:%.*]] = copy_value [[CALL]] : $C
1642
+ // CHECK: begin_borrow [[COPY1]] : $C
1643
+ // CHECK: destroy_value [[CALL]] : $C
1644
+ // CHECK: br bb3(%{{.*}} : $C, [[COPY1]] : $C)
1645
+ // CHECK: bb2:
1646
+ // CHECK: begin_borrow %0 : $C
1647
+ // CHECK: br bb3(%{{.*}} : $C, %0 : $C)
1648
+ // CHECK: bb3(%{{.*}} : @guaranteed $C, [[COPYPHI:%.*]] : @owned $C):
1649
+ // CHECK: end_borrow
1650
+ // CHECK: destroy_value [[COPYPHI]] : $C
1651
+ // CHECK-LABEL: } // end sil function 'testOwnedReborrow'
1652
+ sil [ossa] @testOwnedReborrow : $@convention(thin) (@owned C) -> () {
1653
+ bb0(%0 : @owned $C):
1654
+ cond_br undef, bb1, bb2
1655
+ bb1:
1656
+ destroy_value %0 : $C
1657
+ %f = function_ref @getOwnedC : $@convention(thin) () -> (@owned C)
1658
+ %owned1 = apply %f() : $@convention(thin) () -> (@owned C)
1659
+ %copy1 = copy_value %owned1 : $C
1660
+ %borrow1 = begin_borrow %copy1 : $C
1661
+ destroy_value %owned1 : $C
1662
+ br bb3(%borrow1 : $C, %copy1 : $C)
1663
+ bb2:
1664
+ %borrow2 = begin_borrow %0 : $C
1665
+ br bb3(%borrow2 : $C, %0 : $C)
1666
+ bb3(%borrow3 : @guaranteed $C, %copy3 : @owned $C):
1667
+ end_borrow %borrow3 : $C
1668
+ destroy_value %copy3 : $C
1669
+ %result = tuple ()
1670
+ return %result : $()
1671
+ }
0 commit comments