mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user