@@ -3980,8 +3980,8 @@ namespace {
3980
3980
if (decl->getTemplatedKind () == clang::FunctionDecl::TK_FunctionTemplate)
3981
3981
return ;
3982
3982
3983
- if (! result->getASTContext (). LangOpts . hasFeature (
3984
- Feature::LifetimeDependence))
3983
+ auto &ASTContext = result->getASTContext ();
3984
+ if (!ASTContext. LangOpts . hasFeature ( Feature::LifetimeDependence))
3985
3985
return ;
3986
3986
3987
3987
SmallVector<LifetimeDependenceInfo, 1 > lifetimeDependencies;
@@ -4013,9 +4013,11 @@ namespace {
4013
4013
const auto dependencyVecSize = swiftParams->size () + hasSelf;
4014
4014
SmallBitVector inheritLifetimeParamIndicesForReturn (dependencyVecSize);
4015
4015
SmallBitVector scopedLifetimeParamIndicesForReturn (dependencyVecSize);
4016
+ SmallBitVector paramHasAnnotation (dependencyVecSize);
4016
4017
std::map<unsigned , SmallBitVector> inheritedArgDependences;
4017
4018
auto processLifetimeBound = [&](unsigned idx, Type ty) {
4018
4019
warnForEscapableReturnType ();
4020
+ paramHasAnnotation[idx] = true ;
4019
4021
if (ty->isEscapable ())
4020
4022
scopedLifetimeParamIndicesForReturn[idx] = true ;
4021
4023
else
@@ -4039,6 +4041,7 @@ namespace {
4039
4041
param == clang::LifetimeCaptureByAttr::INVALID)
4040
4042
continue ;
4041
4043
4044
+ paramHasAnnotation[idx] = true ;
4042
4045
if (isa<clang::CXXMethodDecl>(decl) &&
4043
4046
param == clang::LifetimeCaptureByAttr::THIS) {
4044
4047
auto [it, inserted] = inheritedArgDependences.try_emplace (
@@ -4110,6 +4113,19 @@ namespace {
4110
4113
LifetimeDependenceInfoRequest{result},
4111
4114
Impl.SwiftContext .AllocateCopy (lifetimeDependencies));
4112
4115
}
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
+ }
4113
4129
Impl.diagnoseTargetDirectly (decl);
4114
4130
}
4115
4131
0 commit comments