Skip to content

Commit 1021519

Browse files
committed
[TempRValueOpt] NFC: Assert no copy of uncopyable.
1 parent c21338a commit 1021519

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

lib/SILOptimizer/Transforms/TempRValueElimination.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,17 @@ void TempRValueOptPass::tryOptimizeCopyIntoTemp(CopyAddrInst *copyInst) {
616616
if (lastLoadInst == copyInst)
617617
return true;
618618
if (auto *cai = dyn_cast<CopyAddrInst>(lastLoadInst)) {
619-
return cai->getSrc() != tempObj || !cai->isTakeOfSrc();
619+
auto retval = cai->getSrc() != tempObj || !cai->isTakeOfSrc();
620+
assert(!tempObj->getType().isMoveOnly() ||
621+
!retval && "introducing copy of move-only value!?");
622+
return retval;
620623
}
621624
if (auto *li = dyn_cast<LoadInst>(lastLoadInst)) {
622-
return li->getOperand() != tempObj ||
623-
li->getOwnershipQualifier() != LoadOwnershipQualifier::Take;
625+
auto retval = li->getOperand() != tempObj ||
626+
li->getOwnershipQualifier() != LoadOwnershipQualifier::Take;
627+
assert(!tempObj->getType().isMoveOnly() ||
628+
!retval && "introducing copy of move-only value!?");
629+
return retval;
624630
}
625631
return true;
626632
}();

test/SILOptimizer/temp_rvalue_opt_ossa.sil

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ sil @unknown : $@convention(thin) () -> ()
5050
sil [ossa] @guaranteed_user : $@convention(thin) (@guaranteed Klass) -> ()
5151
sil [ossa] @guaranteed_user_with_result : $@convention(thin) (@guaranteed Klass) -> @out Klass
5252
sil [ossa] @inguaranteed_user_without_result_NTS : $@convention(thin) (@in_guaranteed NonTrivialStruct) -> ()
53+
sil [ossa] @inguaranteed_user_without_result_MOS : $@convention(thin) (@in_guaranteed MOS) -> ()
5354

5455
sil [ossa] @inguaranteed_user_without_result : $@convention(thin) (@in_guaranteed Klass) -> () {
5556
bb0(%0 : $*Klass):
@@ -1686,6 +1687,34 @@ entry(%out : $*Klass):
16861687
return %retval : $()
16871688
}
16881689

1690+
// CHECK-LABEL: sil [ossa] @take_from_original_copy_addr__final_use_apply__move_only : {{.*}} {
1691+
// CHECK: [[GET:%[^,]+]] = function_ref @getMOS
1692+
// CHECK: [[USER:%[^,]+]] = function_ref @inguaranteed_user_without_result_MOS
1693+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[GET]]()
1694+
// CHECK: [[SRC:%[^,]+]] = alloc_stack $MOS
1695+
// CHECK: store [[INSTANCE]] to [init] [[SRC]]
1696+
// CHECK: apply [[USER]]([[SRC]])
1697+
// CHECK: apply [[USER]]([[SRC]])
1698+
// CHECK: destroy_addr [[SRC]]
1699+
// CHECK: dealloc_stack [[SRC]]
1700+
// CHECK-LABEL: } // end sil function 'take_from_original_copy_addr__final_use_apply__move_only'
1701+
sil [ossa] @take_from_original_copy_addr__final_use_apply__move_only : $() -> () {
1702+
%getMOS = function_ref @getMOS : $@convention(thin) () -> @owned MOS
1703+
%user = function_ref @inguaranteed_user_without_result_MOS : $@convention(thin) (@in_guaranteed MOS) -> ()
1704+
%instance_1 = apply %getMOS() : $@convention(thin) () -> @owned MOS
1705+
%src = alloc_stack $MOS
1706+
store %instance_1 to [init] %src : $*MOS
1707+
apply %user(%src) : $@convention(thin) (@in_guaranteed MOS) -> ()
1708+
%tmp = alloc_stack $MOS
1709+
copy_addr [take] %src to [init] %tmp : $*MOS
1710+
apply %user(%tmp) : $@convention(thin) (@in_guaranteed MOS) -> ()
1711+
destroy_addr %tmp : $*MOS
1712+
dealloc_stack %tmp : $*MOS
1713+
dealloc_stack %src : $*MOS
1714+
%tuple = tuple ()
1715+
return %tuple : $()
1716+
}
1717+
16891718
// This does not get optimized correctly because of the conservative treatment of load_borrow/end_borrow in MemBehavior
16901719
// CHECK-LABEL: sil [ossa] @test_temprvoborrowboundary1 :
16911720
// CHECK: copy_addr

0 commit comments

Comments
 (0)