[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 22 00:44:58 PDT 2024


================
@@ -269,6 +271,40 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
   }
 }
 
+static bool IsPointerLikeType(QualType QT) {
+  QT = QT.getNonReferenceType();
+  // if (QT->isPointerType())
+  //   return true;
+  auto *RD = QT->getAsCXXRecordDecl();
+  if (!RD)
+    return false;
+  RD = RD->getCanonicalDecl();
+  if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
+    RD = CTSD->getSpecializedTemplate()->getTemplatedDecl();
+  return RD->hasAttr<PointerAttr>();
+}
+
+void Sema::inferLifetimeCaptureByAttribute(FunctionDecl *FD) {
----------------
hokein wrote:

Since we do the auto inference for some STL types, it would be better to have some lit-tests to verify the AST node, e.g. make sure the `lifetime_capture_by` is present. 

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


More information about the cfe-commits mailing list