[clang] Reapply "[clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #115823)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 12 10:07:57 PST 2024


================
@@ -3919,7 +3919,24 @@ static void HandleLifetimeCaptureByAttr(Sema &S, Decl *D,
 
 void Sema::LazyProcessLifetimeCaptureByParams(FunctionDecl *FD) {
   bool HasImplicitThisParam = isInstanceMethod(FD);
-
+  SmallVector<LifetimeCaptureByAttr *, 1> Attrs;
+  for (ParmVarDecl *PVD : FD->parameters())
+    if (auto *A = PVD->getAttr<LifetimeCaptureByAttr>())
+      Attrs.push_back(A);
+  if (HasImplicitThisParam) {
+    TypeSourceInfo *TSI = FD->getTypeSourceInfo();
+    if (!TSI)
+      return;
+    AttributedTypeLoc ATL;
+    for (TypeLoc TL = TSI->getTypeLoc();
+         (ATL = TL.getAsAdjusted<AttributedTypeLoc>());
+         TL = ATL.getModifiedLoc()) {
+      if (auto *A = ATL.getAttrAs<LifetimeCaptureByAttr>())
+        Attrs.push_back(const_cast<LifetimeCaptureByAttr *>(A));
+    }
+  }
+  if (Attrs.empty())
+    return;
----------------
Xazax-hun wrote:

I mean if we have a more convenient way to remember that the currently processed function has these attributes instead of looking them up (like storing a bit when we first see this attribute). But if there is no convenient way to do this I am fine with this as is. 

https://github.com/llvm/llvm-project/pull/115823


More information about the cfe-commits mailing list