Skip to content

Commit 0986bd0

Browse files
committed
[no-implicit-copy] Make sure that we eliminate initial copy_value from [no_copy] cases like we do for moveonly.
Just missed pattern matching the copyable_to_moveonlywrapper at the beginning of the initialization sequence. rdar://104935447
1 parent 282164c commit 0986bd0

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyObjectChecker.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,14 @@ void MoveOnlyChecker::check(DominanceInfo *domTree, PostOrderAnalysis *poa) {
554554
if (!diagnosticEmitter.emittedDiagnosticForValue(markedInst)) {
555555
if (markedInst->getCheckKind() == MarkMustCheckInst::CheckKind::NoCopy) {
556556
if (auto *cvi = dyn_cast<CopyValueInst>(markedInst->getOperand())) {
557-
if (auto *arg = dyn_cast<SILFunctionArgument>(cvi->getOperand())) {
557+
SingleValueInstruction *i = cvi;
558+
if (auto *copyToMoveOnly =
559+
dyn_cast<CopyableToMoveOnlyWrapperValueInst>(
560+
cvi->getOperand())) {
561+
i = copyToMoveOnly;
562+
}
563+
564+
if (auto *arg = dyn_cast<SILFunctionArgument>(i->getOperand(0))) {
558565
if (arg->getOwnershipKind() == OwnershipKind::Guaranteed) {
559566
for (auto *use : markedInst->getConsumingUses()) {
560567
destroys.push_back(cast<DestroyValueInst>(use->getUser()));

test/SILOptimizer/noimplicitcopy.sil

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -sil-move-only-object-checker %s
2+
3+
//////////////////
4+
// Declarations //
5+
//////////////////
6+
7+
class Klass {}
8+
9+
sil @classUseMoveOnlyWithoutEscaping : $@convention(thin) (@guaranteed Klass) -> ()
10+
11+
///////////
12+
// Tests //
13+
///////////
14+
15+
// This test makes sure that we eliminate %2 after checking and that
16+
// sil-verify-all does not trigger.
17+
sil [ossa] @test_remove_early_copyvalue : $@convention(thin) (@guaranteed Klass) -> () {
18+
bb0(%0 : @noImplicitCopy @guaranteed $Klass):
19+
%1 = copyable_to_moveonlywrapper [guaranteed] %0 : $Klass
20+
%2 = copy_value %1 : $@moveOnly Klass
21+
%3 = mark_must_check [no_copy] %2 : $@moveOnly Klass
22+
debug_value %3 : $@moveOnly Klass, let, name "x2", argno 1
23+
%5 = begin_borrow %3 : $@moveOnly Klass
24+
%6 = function_ref @classUseMoveOnlyWithoutEscaping : $@convention(thin) (@guaranteed Klass) -> ()
25+
%7 = moveonlywrapper_to_copyable [guaranteed] %5 : $@moveOnly Klass
26+
%8 = apply %6(%7) : $@convention(thin) (@guaranteed Klass) -> ()
27+
end_borrow %5 : $@moveOnly Klass
28+
destroy_value %3 : $@moveOnly Klass
29+
%11 = tuple ()
30+
return %11 : $()
31+
}

0 commit comments

Comments
 (0)