@@ -3980,8 +3980,8 @@ namespace {
39803980 if (decl->getTemplatedKind () == clang::FunctionDecl::TK_FunctionTemplate)
39813981 return ;
39823982
3983- if (! result->getASTContext (). LangOpts . hasFeature (
3984- Feature::LifetimeDependence))
3983+ auto &ASTContext = result->getASTContext ();
3984+ if (!ASTContext. LangOpts . hasFeature ( Feature::LifetimeDependence))
39853985 return ;
39863986
39873987 SmallVector<LifetimeDependenceInfo, 1 > lifetimeDependencies;
@@ -4013,9 +4013,11 @@ namespace {
40134013 const auto dependencyVecSize = swiftParams->size () + hasSelf;
40144014 SmallBitVector inheritLifetimeParamIndicesForReturn (dependencyVecSize);
40154015 SmallBitVector scopedLifetimeParamIndicesForReturn (dependencyVecSize);
4016+ SmallBitVector paramHasAnnotation (dependencyVecSize);
40164017 std::map<unsigned , SmallBitVector> inheritedArgDependences;
40174018 auto processLifetimeBound = [&](unsigned idx, Type ty) {
40184019 warnForEscapableReturnType ();
4020+ paramHasAnnotation[idx] = true ;
40194021 if (ty->isEscapable ())
40204022 scopedLifetimeParamIndicesForReturn[idx] = true ;
40214023 else
@@ -4039,6 +4041,7 @@ namespace {
40394041 param == clang::LifetimeCaptureByAttr::INVALID)
40404042 continue ;
40414043
4044+ paramHasAnnotation[idx] = true ;
40424045 if (isa<clang::CXXMethodDecl>(decl) &&
40434046 param == clang::LifetimeCaptureByAttr::THIS) {
40444047 auto [it, inserted] = inheritedArgDependences.try_emplace (
@@ -4110,6 +4113,19 @@ namespace {
41104113 LifetimeDependenceInfoRequest{result},
41114114 Impl.SwiftContext .AllocateCopy (lifetimeDependencies));
41124115 }
4116+ if (ASTContext.LangOpts .hasFeature (Feature::AllowUnsafeAttribute) &&
4117+ ASTContext.LangOpts .hasFeature (Feature::SafeInterop)) {
4118+ for (auto [idx, param] : llvm::enumerate (decl->parameters ())) {
4119+ if (swiftParams->get (idx)->getInterfaceType ()->isEscapable ())
4120+ continue ;
4121+ if (param->hasAttr <clang::NoEscapeAttr>() || paramHasAnnotation[idx])
4122+ continue ;
4123+ // We have a nonescapabe parameter that does not have its lifetime
4124+ // annotated nor is it marked noescape.
4125+ auto attr = new (ASTContext) UnsafeAttr (/* implicit=*/ true );
4126+ result->getAttrs ().add (attr);
4127+ }
4128+ }
41134129 Impl.diagnoseTargetDirectly (decl);
41144130 }
41154131
0 commit comments