Skip to content

Commit b8134db

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 bb67d1e commit b8134db

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,16 +1344,17 @@ bool GatherLexicalLifetimeUseVisitor::visitUse(Operand *op,
13441344
// are going to try and extend move checking into the partial apply using
13451345
// cloning to eliminate destroys or reinits.
13461346
if (auto fas = FullApplySite::isa(op->getUser())) {
1347-
if (stripAccessMarkers(op->get()) != useState.address) {
1347+
auto convention = fas.getCaptureConvention(*op);
1348+
if (convention != SILArgumentConvention::Indirect_Inout &&
1349+
stripAccessMarkers(op->get()) != useState.address) {
13481350
LLVM_DEBUG(
13491351
llvm::dbgs()
13501352
<< "!!! Error! Found consuming closure use not on base address: "
13511353
<< *op->getUser());
13521354
return false;
13531355
}
13541356

1355-
if (fas.getCaptureConvention(*op) ==
1356-
SILArgumentConvention::Indirect_InoutAliasable) {
1357+
if (convention == SILArgumentConvention::Indirect_InoutAliasable) {
13571358
// If we don't find the function, we can't handle this, so bail.
13581359
auto *func = fas.getCalleeFunction();
13591360
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)