Skip to content

Commit 1765f0b

Browse files
committed
[MoveOnly] Fix consume of addr with mutated field.
Don't fail out of use visitation when encountering an apply which uses a field of the value as an inout parameter. rdar://139666145
1 parent dcde328 commit 1765f0b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,8 +1341,10 @@ bool GatherLexicalLifetimeUseVisitor::visitUse(Operand *op,
13411341
}
13421342

13431343
if (auto fas = FullApplySite::isa(op->getUser())) {
1344-
// Bail on apply uses of fields.
1345-
if (stripAccessMarkers(op->get()) != useState.address) {
1344+
auto convention = fas.getCaptureConvention(*op);
1345+
// Bail on non-inout apply uses of fields.
1346+
if (convention != SILArgumentConvention::Indirect_Inout &&
1347+
stripAccessMarkers(op->get()) != useState.address) {
13461348
LLVM_DEBUG(
13471349
llvm::dbgs()
13481350
<< "!!! Error! Found consuming closure use not on base address: "
@@ -1353,8 +1355,7 @@ bool GatherLexicalLifetimeUseVisitor::visitUse(Operand *op,
13531355
// Then see if we have an inout_aliasable full apply site use. In that case,
13541356
// we are going to try and extend move checking into the partial apply
13551357
// using cloning to eliminate destroys or reinits.
1356-
if (fas.getCaptureConvention(*op) ==
1357-
SILArgumentConvention::Indirect_InoutAliasable) {
1358+
if (convention == SILArgumentConvention::Indirect_InoutAliasable) {
13581359
// If we don't find the function, we can't handle this, so bail.
13591360
auto *func = fas.getCalleeFunction();
13601361
if (!func || !func->isDefer())
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-build-swift %s
2+
3+
struct Box<T> { var value: T }
4+
5+
func modify(_ string: inout String) {}
6+
7+
func tryConsume() {
8+
var box = Box(value: "")
9+
modify(&box.value)
10+
print(consume box)
11+
}

0 commit comments

Comments
 (0)