Skip to content

[MoveOnly] Fix consume of addr with mutated field. #81541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1340,20 +1340,22 @@ bool GatherLexicalLifetimeUseVisitor::visitUse(Operand *op,
return true;
}

// Then see if we have a inout_aliasable full apply site use. In that case, we
// are going to try and extend move checking into the partial apply using
// cloning to eliminate destroys or reinits.
if (auto fas = FullApplySite::isa(op->getUser())) {
if (stripAccessMarkers(op->get()) != useState.address) {
auto convention = fas.getCaptureConvention(*op);
// Bail on non-inout apply uses of fields.
if (convention != SILArgumentConvention::Indirect_Inout &&
stripAccessMarkers(op->get()) != useState.address) {
LLVM_DEBUG(
llvm::dbgs()
<< "!!! Error! Found consuming closure use not on base address: "
<< *op->getUser());
return false;
}

if (fas.getCaptureConvention(*op) ==
SILArgumentConvention::Indirect_InoutAliasable) {
// Then see if we have an inout_aliasable full apply site use. In that case,
// we are going to try and extend move checking into the partial apply
// using cloning to eliminate destroys or reinits.
if (convention == SILArgumentConvention::Indirect_InoutAliasable) {
// If we don't find the function, we can't handle this, so bail.
auto *func = fas.getCalleeFunction();
if (!func || !func->isDefer())
Expand Down
11 changes: 11 additions & 0 deletions validation-test/SILOptimizer/rdar139666145.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %target-build-swift %s

struct Box<T> { var value: T }

func modify(_ string: inout String) {}

func tryConsume() {
var box = Box(value: "")
modify(&box.value)
print(consume box)
}