@@ -3857,6 +3857,18 @@ namespace {
3857
3857
if (decl->getTemplatedKind() == clang::FunctionDecl::TK_FunctionTemplate)
3858
3858
return;
3859
3859
3860
+ SmallVector<LifetimeDependenceInfo, 1> lifetimeDependencies;
3861
+ LifetimeDependenceInfo immortalLifetime(nullptr, nullptr, 0,
3862
+ /*isImmortal*/ true);
3863
+ if (const auto *funDecl = dyn_cast<FuncDecl>(result))
3864
+ if (hasUnsafeAPIAttr(decl) && !funDecl->getResultInterfaceType()->isEscapable()) {
3865
+ Impl.SwiftContext.evaluator.cacheOutput(
3866
+ LifetimeDependenceInfoRequest{result},
3867
+ Impl.SwiftContext.AllocateCopy(lifetimeDependencies));
3868
+ lifetimeDependencies.push_back(immortalLifetime);
3869
+ return;
3870
+ }
3871
+
3860
3872
auto retType = decl->getReturnType();
3861
3873
auto warnForEscapableReturnType = [&] {
3862
3874
if (isEscapableAnnotatedType(retType.getTypePtr())) {
@@ -3869,8 +3881,8 @@ namespace {
3869
3881
};
3870
3882
3871
3883
auto swiftParams = result->getParameters();
3872
- bool hasSelf = result->hasImplicitSelfDecl() && !isa<ConstructorDecl>(result);
3873
- SmallVector<LifetimeDependenceInfo, 1> lifetimeDependencies ;
3884
+ bool hasSelf =
3885
+ result->hasImplicitSelfDecl() && !isa<ConstructorDecl>(result) ;
3874
3886
SmallBitVector inheritLifetimeParamIndicesForReturn(swiftParams->size() +
3875
3887
hasSelf);
3876
3888
SmallBitVector scopedLifetimeParamIndicesForReturn(swiftParams->size() +
@@ -3910,8 +3922,7 @@ namespace {
3910
3922
// Assume default constructed view types have no dependencies.
3911
3923
if (ctordecl->isDefaultConstructor() &&
3912
3924
importer::hasNonEscapableAttr(ctordecl->getParent()))
3913
- lifetimeDependencies.push_back(
3914
- LifetimeDependenceInfo(nullptr, nullptr, 0, /*isImmortal*/ true));
3925
+ lifetimeDependencies.push_back(immortalLifetime);
3915
3926
}
3916
3927
if (lifetimeDependencies.empty()) {
3917
3928
if (isNonEscapableAnnotatedType(retType.getTypePtr())) {
0 commit comments