Skip to content

Commit c2836af

Browse files
committed
Fix getLoweredOwnership() for setters of ~Escapable types
1 parent 90f9fce commit c2836af

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/AST/LifetimeDependence.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,18 @@ void LifetimeDependenceInfo::Profile(llvm::FoldingSetNodeID &ID) const {
186186
}
187187
}
188188

189-
// Warning: this is incorrect for Setter 'newValue' parameters. It should only
190-
// be called for a Setter's 'self'.
191-
static ValueOwnership getLoweredOwnership(AbstractFunctionDecl *afd) {
189+
static ValueOwnership getLoweredOwnership(ParamDecl *param,
190+
AbstractFunctionDecl *afd) {
192191
if (isa<ConstructorDecl>(afd)) {
193192
return ValueOwnership::Owned;
194193
}
195194
if (auto *ad = dyn_cast<AccessorDecl>(afd)) {
196-
if (ad->getAccessorKind() == AccessorKind::Set ||
197-
isYieldingMutableAccessor(ad->getAccessorKind())) {
195+
if (ad->getAccessorKind() == AccessorKind::Set) {
196+
return param->isSelfParameter() ? ValueOwnership::InOut
197+
: ValueOwnership::Owned;
198+
}
199+
if (isYieldingMutableAccessor(ad->getAccessorKind())) {
200+
assert(param->isSelfParameter());
198201
return ValueOwnership::InOut;
199202
}
200203
}

0 commit comments

Comments
 (0)