Skip to content

Commit b5d242a

Browse files
committed
MoveOnlyChecker: Don't follow trivial transitive uses of borrows.
Trivial values don't have ownership tracked, so their uses can't affect the lifetime of the original borrow. Fixes rdar://148457155.
1 parent dccbcf3 commit b5d242a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,9 @@ struct CopiedLoadBorrowEliminationVisitor
17411741
// Look through borrows.
17421742
for (auto value : nextUse->getUser()->getResults()) {
17431743
for (auto *use : value->getUses()) {
1744+
if (use->get()->getType().isTrivial(*use->getFunction())) {
1745+
continue;
1746+
}
17441747
useWorklist.push_back(use);
17451748
}
17461749
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-swift-frontend -emit-sil -verify %s
2+
3+
func use(_: Int32) {}
4+
5+
struct NoncopyableYieldingSubscript: ~Copyable {
6+
subscript() -> Int16 {
7+
_read {
8+
yield 0
9+
}
10+
}
11+
}
12+
13+
func foo(component: inout NoncopyableYieldingSubscript, condition: Bool) {
14+
let extracted: Int32
15+
16+
switch condition {
17+
case true:
18+
extracted = Int32(component[])
19+
20+
case false:
21+
extracted = Int32(component[])
22+
23+
}
24+
25+
use(extracted)
26+
}

0 commit comments

Comments
 (0)