Skip to content

Commit 590dab4

Browse files
committed
ClangImporter: fix C++ memberwise inits to use @Lifetime(immortal)
_unsafeNonEscapableResult no longer dsiables diagnostics at the call site. We need to use a proper lifetime annotation for that.
1 parent a71c6a3 commit 590dab4

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,9 +2036,20 @@ namespace {
20362036
}
20372037

20382038
void markReturnsUnsafeNonescapable(AbstractFunctionDecl *fd) {
2039-
fd->getAttrs().add(new (Impl.SwiftContext)
2040-
UnsafeNonEscapableResultAttr(/*Implicit=*/true));
20412039
fd->getAttrs().add(new (Impl.SwiftContext) UnsafeAttr(/*Implicit=*/true));
2040+
2041+
unsigned resultIndex = fd->getParameters()->size();
2042+
if (fd->hasImplicitSelfDecl()) {
2043+
++resultIndex;
2044+
}
2045+
SmallVector<LifetimeDependenceInfo, 1> lifetimeDependencies;
2046+
LifetimeDependenceInfo immortalLifetime(nullptr, nullptr, resultIndex,
2047+
/*isImmortal*/ true);
2048+
lifetimeDependencies.push_back(immortalLifetime);
2049+
Impl.SwiftContext.evaluator.cacheOutput(
2050+
LifetimeDependenceInfoRequest{fd},
2051+
Impl.SwiftContext.AllocateCopy(lifetimeDependencies));
2052+
return;
20422053
}
20432054

20442055
Decl *VisitRecordDecl(const clang::RecordDecl *decl) {
@@ -4060,6 +4071,9 @@ namespace {
40604071
CxxEscapability::Unknown) != CxxEscapability::NonEscapable;
40614072
};
40624073

4074+
// FIXME: this uses '0' as the result index. That only works for
4075+
// standalone functions with no parameters.
4076+
// See markReturnsUnsafeNonescapable() for a general approach.
40634077
auto &ASTContext = result->getASTContext();
40644078
SmallVector<LifetimeDependenceInfo, 1> lifetimeDependencies;
40654079
LifetimeDependenceInfo immortalLifetime(nullptr, nullptr, 0,

0 commit comments

Comments
 (0)