Skip to content

Commit 3f67cab

Browse files
authored
Merge pull request #67224 from gottesmm/release-5.9-rdar112028837
[5.9][move-only] Ensure that copyable borrowing parameters of resilient type used by a function in the same module can be recognized by the checker
2 parents eda4d7a + ed01e38 commit 3f67cab

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerUtils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ bool swift::siloptimizer::searchForCandidateObjectMarkMustChecks(
267267
}
268268
}
269269

270+
// Handle guaranteed parameters of a resilient type used by a resilient
271+
// function inside the module in which the resilient type is defined.
272+
if (auto *cvi = dyn_cast<CopyValueInst>(mmci->getOperand())) {
273+
if (auto *cmi = dyn_cast<CopyableToMoveOnlyWrapperValueInst>(cvi->getOperand())) {
274+
if (auto *lbi = dyn_cast<LoadBorrowInst>(cmi->getOperand())) {
275+
if (auto *arg = dyn_cast<SILFunctionArgument>(lbi->getOperand())) {
276+
if (arg->getKnownParameterInfo().isIndirectInGuaranteed()) {
277+
moveIntroducersToProcess.insert(mmci);
278+
continue;
279+
}
280+
}
281+
}
282+
}
283+
}
284+
285+
270286
// If we see a mark_must_check that is marked no implicit copy that we
271287
// don't understand, emit a diagnostic to fail the compilation. This
272288
// ensures that if someone marks something no implicit copy and we fail to

test/SILOptimizer/moveonly_addresschecker_diagnostics_library_evolution.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ public class CopyableKlass {
1717
var letS = NonEmptyStruct()
1818
}
1919

20+
public struct CopyableStruct {
21+
var k = CopyableKlass()
22+
}
23+
2024
public func borrowVal(_ x: borrowing NonEmptyStruct) {}
2125
public func borrowVal(_ x: borrowing EmptyStruct) {}
26+
public func borrowVal(_ x: borrowing CopyableKlass) {}
27+
public func borrowVal(_ x: borrowing CopyableStruct) {}
28+
public func consumeVal(_ x: consuming CopyableKlass) {}
2229
public func consumeVal(_ x: consuming NonEmptyStruct) {}
2330
public func consumeVal(_ x: consuming EmptyStruct) {}
2431

test/SILOptimizer/noimplicitcopy.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
class Klass {}
88

9+
struct CopyableStruct {
10+
var k = Klass()
11+
}
12+
913
sil @classUseMoveOnlyWithoutEscaping : $@convention(thin) (@guaranteed Klass) -> ()
1014

1115
///////////
@@ -29,3 +33,16 @@ bb0(%0 : @noImplicitCopy @guaranteed $Klass):
2933
%11 = tuple ()
3034
return %11 : $()
3135
}
36+
37+
sil [ossa] @testSimpleBorrowParameter : $@convention(thin) (@in_guaranteed CopyableStruct) -> () {
38+
bb0(%0 : @noImplicitCopy $*CopyableStruct):
39+
%1 = load_borrow %0 : $*CopyableStruct // users: %7, %2
40+
%2 = copyable_to_moveonlywrapper [guaranteed] %1 : $CopyableStruct // user: %3
41+
%3 = copy_value %2 : $@moveOnly CopyableStruct // user: %4
42+
%4 = mark_must_check [no_consume_or_assign] %3 : $@moveOnly CopyableStruct // users: %6, %5
43+
debug_value %4 : $@moveOnly CopyableStruct, let, name "x", argno 1 // id: %5
44+
destroy_value %4 : $@moveOnly CopyableStruct // id: %6
45+
end_borrow %1 : $CopyableStruct // id: %7
46+
%8 = tuple () // user: %9
47+
return %8 : $() // id: %9
48+
}

0 commit comments

Comments
 (0)