@@ -3876,8 +3876,8 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
3876
3876
<< AL.getRange ();
3877
3877
return nullptr ;
3878
3878
}
3879
- SmallVector<IdentifierInfo *, 1 > ParamIdents;
3880
- SmallVector<SourceLocation, 1 > ParamLocs;
3879
+ SmallVector<IdentifierInfo *> ParamIdents;
3880
+ SmallVector<SourceLocation> ParamLocs;
3881
3881
for (unsigned I = 0 ; I < AL.getNumArgs (); ++I) {
3882
3882
if (AL.isArgExpr (I)) {
3883
3883
Expr *E = AL.getArgAsExpr (I);
@@ -3894,15 +3894,15 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
3894
3894
ParamIdents.push_back (IdLoc->Ident );
3895
3895
ParamLocs.push_back (IdLoc->Loc );
3896
3896
}
3897
- SmallVector<int , 1 > FakeParamIndices (ParamIdents.size (),
3898
- LifetimeCaptureByAttr::INVALID);
3897
+ SmallVector<int > FakeParamIndices (ParamIdents.size (),
3898
+ LifetimeCaptureByAttr::INVALID);
3899
3899
LifetimeCaptureByAttr *CapturedBy = ::new (Context) LifetimeCaptureByAttr (
3900
3900
Context, AL, FakeParamIndices.data (), FakeParamIndices.size ());
3901
3901
CapturedBy->setArgs (std::move (ParamIdents), std::move (ParamLocs));
3902
3902
return CapturedBy;
3903
3903
}
3904
3904
3905
- static void HandleLifetimeCaptureByAttr (Sema &S, Decl *D,
3905
+ static void handleLifetimeCaptureByAttr (Sema &S, Decl *D,
3906
3906
const ParsedAttr &AL) {
3907
3907
// Do not allow multiple attributes.
3908
3908
if (D->hasAttr <LifetimeCaptureByAttr>()) {
@@ -3919,7 +3919,24 @@ static void HandleLifetimeCaptureByAttr(Sema &S, Decl *D,
3919
3919
3920
3920
void Sema::LazyProcessLifetimeCaptureByParams (FunctionDecl *FD) {
3921
3921
bool HasImplicitThisParam = isInstanceMethod (FD);
3922
-
3922
+ SmallVector<LifetimeCaptureByAttr *, 1 > Attrs;
3923
+ for (ParmVarDecl *PVD : FD->parameters ())
3924
+ if (auto *A = PVD->getAttr <LifetimeCaptureByAttr>())
3925
+ Attrs.push_back (A);
3926
+ if (HasImplicitThisParam) {
3927
+ TypeSourceInfo *TSI = FD->getTypeSourceInfo ();
3928
+ if (!TSI)
3929
+ return ;
3930
+ AttributedTypeLoc ATL;
3931
+ for (TypeLoc TL = TSI->getTypeLoc ();
3932
+ (ATL = TL.getAsAdjusted <AttributedTypeLoc>());
3933
+ TL = ATL.getModifiedLoc ()) {
3934
+ if (auto *A = ATL.getAttrAs <LifetimeCaptureByAttr>())
3935
+ Attrs.push_back (const_cast <LifetimeCaptureByAttr *>(A));
3936
+ }
3937
+ }
3938
+ if (Attrs.empty ())
3939
+ return ;
3923
3940
llvm::StringMap<int > NameIdxMapping;
3924
3941
NameIdxMapping[" global" ] = LifetimeCaptureByAttr::GLOBAL;
3925
3942
NameIdxMapping[" unknown" ] = LifetimeCaptureByAttr::UNKNOWN;
@@ -3936,9 +3953,7 @@ void Sema::LazyProcessLifetimeCaptureByParams(FunctionDecl *FD) {
3936
3953
Diag (PVD->getLocation (), diag::err_capture_by_param_uses_reserved_name)
3937
3954
<< (PVD->getName () == " unknown" );
3938
3955
};
3939
- auto HandleCaptureBy = [&](LifetimeCaptureByAttr *CapturedBy) {
3940
- if (!CapturedBy)
3941
- return ;
3956
+ for (auto *CapturedBy : Attrs) {
3942
3957
const auto &Entities = CapturedBy->getArgIdents ();
3943
3958
for (size_t I = 0 ; I < Entities.size (); ++I) {
3944
3959
StringRef Name = Entities[I]->getName ();
@@ -3956,22 +3971,6 @@ void Sema::LazyProcessLifetimeCaptureByParams(FunctionDecl *FD) {
3956
3971
DisallowReservedParams (Name);
3957
3972
CapturedBy->setParamIdx (I, It->second );
3958
3973
}
3959
- };
3960
- for (ParmVarDecl *PVD : FD->parameters ())
3961
- HandleCaptureBy (PVD->getAttr <LifetimeCaptureByAttr>());
3962
- if (!HasImplicitThisParam)
3963
- return ;
3964
- TypeSourceInfo *TSI = FD->getTypeSourceInfo ();
3965
- if (!TSI)
3966
- return ;
3967
- AttributedTypeLoc ATL;
3968
- for (TypeLoc TL = TSI->getTypeLoc ();
3969
- (ATL = TL.getAsAdjusted <AttributedTypeLoc>());
3970
- TL = ATL.getModifiedLoc ()) {
3971
- auto *A = ATL.getAttrAs <LifetimeCaptureByAttr>();
3972
- if (!A)
3973
- continue ;
3974
- HandleCaptureBy (const_cast <LifetimeCaptureByAttr *>(A));
3975
3974
}
3976
3975
}
3977
3976
@@ -6753,7 +6752,7 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
6753
6752
handleCallbackAttr (S, D, AL);
6754
6753
break ;
6755
6754
case ParsedAttr::AT_LifetimeCaptureBy:
6756
- HandleLifetimeCaptureByAttr (S, D, AL);
6755
+ handleLifetimeCaptureByAttr (S, D, AL);
6757
6756
break ;
6758
6757
case ParsedAttr::AT_CalledOnce:
6759
6758
handleCalledOnceAttr (S, D, AL);
0 commit comments