@@ -3857,6 +3857,18 @@ namespace {
38573857 if (decl->getTemplatedKind () == clang::FunctionDecl::TK_FunctionTemplate)
38583858 return ;
38593859
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+
38603872 auto retType = decl->getReturnType ();
38613873 auto warnForEscapableReturnType = [&] {
38623874 if (isEscapableAnnotatedType (retType.getTypePtr ())) {
@@ -3869,8 +3881,8 @@ namespace {
38693881 };
38703882
38713883 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) ;
38743886 SmallBitVector inheritLifetimeParamIndicesForReturn (swiftParams->size () +
38753887 hasSelf);
38763888 SmallBitVector scopedLifetimeParamIndicesForReturn (swiftParams->size () +
@@ -3910,8 +3922,7 @@ namespace {
39103922 // Assume default constructed view types have no dependencies.
39113923 if (ctordecl->isDefaultConstructor () &&
39123924 importer::hasNonEscapableAttr (ctordecl->getParent ()))
3913- lifetimeDependencies.push_back (
3914- LifetimeDependenceInfo (nullptr , nullptr , 0 , /* isImmortal*/ true ));
3925+ lifetimeDependencies.push_back (immortalLifetime);
39153926 }
39163927 if (lifetimeDependencies.empty ()) {
39173928 if (isNonEscapableAnnotatedType (retType.getTypePtr ())) {
0 commit comments