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.
This commit is contained in:
Andrew Trick
2025-03-19 11:00:08 -07:00
parent 955d089a90
commit d41c4d4cc9

View File

@@ -2036,9 +2036,20 @@ namespace {
}
void markReturnsUnsafeNonescapable(AbstractFunctionDecl *fd) {
fd->getAttrs().add(new (Impl.SwiftContext)
UnsafeNonEscapableResultAttr(/*Implicit=*/true));
fd->getAttrs().add(new (Impl.SwiftContext) UnsafeAttr(/*Implicit=*/true));
unsigned resultIndex = fd->getParameters()->size();
if (fd->hasImplicitSelfDecl()) {
++resultIndex;
}
SmallVector<LifetimeDependenceInfo, 1> lifetimeDependencies;
LifetimeDependenceInfo immortalLifetime(nullptr, nullptr, resultIndex,
/*isImmortal*/ true);
lifetimeDependencies.push_back(immortalLifetime);
Impl.SwiftContext.evaluator.cacheOutput(
LifetimeDependenceInfoRequest{fd},
Impl.SwiftContext.AllocateCopy(lifetimeDependencies));
return;
}
Decl *VisitRecordDecl(const clang::RecordDecl *decl) {
@@ -4060,6 +4071,9 @@ namespace {
CxxEscapability::Unknown) != CxxEscapability::NonEscapable;
};
// FIXME: this uses '0' as the result index. That only works for
// standalone functions with no parameters.
// See markReturnsUnsafeNonescapable() for a general approach.
auto &ASTContext = result->getASTContext();
SmallVector<LifetimeDependenceInfo, 1> lifetimeDependencies;
LifetimeDependenceInfo immortalLifetime(nullptr, nullptr, 0,