Skip to content

Commit f4a2e46

Browse files
Merge pull request #81541 from nate-chandler/rdar139666145
[MoveOnly] Fix consume of addr with mutated field.
2 parents 8596b22 + 1765f0b commit f4a2e46

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,20 +1340,22 @@ bool GatherLexicalLifetimeUseVisitor::visitUse(Operand *op,
13401340
return true;
13411341
}
13421342

1343-
// Then see if we have a inout_aliasable full apply site use. In that case, we
1344-
// are going to try and extend move checking into the partial apply using
1345-
// cloning to eliminate destroys or reinits.
13461343
if (auto fas = FullApplySite::isa(op->getUser())) {
1347-
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) {
13481348
LLVM_DEBUG(
13491349
llvm::dbgs()
13501350
<< "!!! Error! Found consuming closure use not on base address: "
13511351
<< *op->getUser());
13521352
return false;
13531353
}
13541354

1355-
if (fas.getCaptureConvention(*op) ==
1356-
SILArgumentConvention::Indirect_InoutAliasable) {
1355+
// Then see if we have an inout_aliasable full apply site use. In that case,
1356+
// we are going to try and extend move checking into the partial apply
1357+
// using cloning to eliminate destroys or reinits.
1358+
if (convention == SILArgumentConvention::Indirect_InoutAliasable) {
13571359
// If we don't find the function, we can't handle this, so bail.
13581360
auto *func = fas.getCalleeFunction();
13591361
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)