Skip to content

Commit 2052d2c

Browse files
committed
Fix MoveOnlyObjectCheckerPImpl::check() for mark_dependence.
Handle the presence of mark_dependence instructions after a begin_apply. Fixes a compiler crash: "copy of noncopyable typed value. This is a compiler bug. ..." (cherry picked from commit 7a29d9d)
1 parent 4cd7f45 commit 2052d2c

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerUtils.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,17 @@ bool MoveOnlyObjectCheckerPImpl::eraseMarkWithCopiedOperand(
497497

498498
auto replacement = cvi->getOperand();
499499
auto orig = replacement;
500-
if (auto *copyToMoveOnly =
501-
dyn_cast<CopyableToMoveOnlyWrapperValueInst>(orig)) {
502-
orig = copyToMoveOnly->getOperand();
500+
while (true) {
501+
if (auto *copyToMoveOnly =
502+
dyn_cast<CopyableToMoveOnlyWrapperValueInst>(orig)) {
503+
orig = copyToMoveOnly->getOperand();
504+
continue;
505+
}
506+
if (auto *markDep = dyn_cast<MarkDependenceInst>(orig)) {
507+
orig = markDep->getValue();
508+
continue;
509+
}
510+
break;
503511
}
504512

505513
// TODO: Instead of pattern matching specific code generation patterns,

test/SILOptimizer/moveonly_objectchecker.sil

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
1-
// RUN: %target-sil-opt -sil-move-only-object-checker -enable-experimental-feature MoveOnlyClasses -enable-sil-verify-all -move-only-diagnostics-silently-emit-diagnostics %s | %FileCheck %s
1+
// RUN: %target-sil-opt -sil-move-only-object-checker -enable-experimental-feature MoveOnlyClasses -enable-experimental-feature Lifetimes -enable-sil-verify-all -move-only-diagnostics-silently-emit-diagnostics %s | %FileCheck %s
22

33
// REQUIRES: swift_feature_MoveOnlyClasses
4+
// REQUIRES: swift_feature_Lifetimes
45

56
sil_stage raw
67

78
import Swift
89

910
class Klass: ~Copyable {}
1011

12+
struct NCNE : ~Copyable, ~Escapable {}
13+
14+
struct NCNEHolder : ~Copyable, ~Escapable {
15+
var ncne: NCNE {
16+
@_lifetime(borrow self)
17+
get
18+
}
19+
}
20+
1121
sil @classUseMoveOnlyWithoutEscaping : $@convention(thin) (@guaranteed Klass) -> ()
1222

23+
sil @read_ncne : $@yield_once @convention(method) (@guaranteed NCNEHolder) -> @lifetime(borrow 0) @yields @guaranteed NCNE
24+
sil @use_ncne : $@convention(thin) (@guaranteed NCNE) -> ()
25+
1326
// CHECK-LABEL: sil [ossa] @chainErrorTest : $@convention(thin) (@guaranteed Klass) -> () {
1427
// CHECK-NOT: copy_value
1528
// CHECK: explicit_copy_value
1629
// CHECK-NOT: copy_value
1730
// CHECK: explicit_copy_value
18-
// CHECK-NOT: copy_value
31+
// CHECK-NOT: copy_valuea
1932
// CHECK: } // end sil function 'chainErrorTest'
2033
sil [ossa] @chainErrorTest : $@convention(thin) (@guaranteed Klass) -> () {
2134
bb0(%0 : @guaranteed $Klass):
@@ -51,3 +64,27 @@ bb0(%0 : @guaranteed $Klass):
5164
%30 = tuple ()
5265
return %30 : $()
5366
}
67+
68+
// CHECK-LABEL: sil [ossa] @testCopyOfMarkDep : $@convention(thin) (@guaranteed NCNEHolder) -> () {
69+
// CHECK-NOT: explicit_copy_value
70+
// CHECK-NOT: copy_value
71+
// CHECK-LABEL: } // end sil function 'testCopyOfMarkDep'
72+
sil [ossa] @testCopyOfMarkDep : $@convention(thin) (@guaranteed NCNEHolder) -> () {
73+
bb0(%0 : @guaranteed $NCNEHolder):
74+
%1 = copy_value %0
75+
%2 = mark_unresolved_non_copyable_value [no_consume_or_assign] %1
76+
debug_value %2, let, name "h", argno 1
77+
%4 = function_ref @read_ncne : $@yield_once @convention(method) (@guaranteed NCNEHolder) -> @lifetime(borrow 0) @yields @guaranteed NCNE
78+
(%5, %6) = begin_apply %4(%2) : $@yield_once @convention(method) (@guaranteed NCNEHolder) -> @lifetime(borrow 0) @yields @guaranteed NCNE
79+
%7 = mark_dependence [unresolved] %5 on %6
80+
%8 = mark_dependence [unresolved] %7 on %2
81+
%9 = copy_value %8
82+
%10 = mark_unresolved_non_copyable_value [no_consume_or_assign] %9
83+
%11 = function_ref @use_ncne : $@convention(thin) (@guaranteed NCNE) -> ()
84+
%12 = apply %11(%10) : $@convention(thin) (@guaranteed NCNE) -> ()
85+
destroy_value %10
86+
%14 = end_apply %6 as $()
87+
destroy_value %2
88+
%16 = tuple ()
89+
return %16
90+
}

0 commit comments

Comments
 (0)