[clang] [Lifetime Safety] Highlight lifetimebound calls in alias chain diagnostics (PR #206337)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 9 04:05:32 PDT 2026


================
@@ -521,19 +529,96 @@ class LifetimeChecker {
     }
   }
 
+  std::optional<LifetimeBoundParamInfo>
+  getLifetimeBoundParamInfo(const FunctionDecl *FD, unsigned I) {
+    const ParmVarDecl *PVD = nullptr;
+    if (const auto *Method = dyn_cast<CXXMethodDecl>(FD);
+        Method && Method->isInstance() && !isa<CXXConstructorDecl>(FD)) {
+      if (I == 0)
+        return implicitObjectParamIsLifetimeBound(Method)
+                   ? std::optional<LifetimeBoundParamInfo>(
+                         LifetimeBoundParamInfo(Method))
+                   : std::nullopt;
+      if ((I - 1) < Method->getNumParams())
+        PVD = Method->getParamDecl(I - 1);
+    } else if (I < FD->getNumParams()) {
+      PVD = FD->getParamDecl(I);
+    }
+
+    if (PVD && PVD->hasAttr<clang::LifetimeBoundAttr>())
+      return LifetimeBoundParamInfo(PVD);
+    return std::nullopt;
+  }
+
+  std::optional<LifetimeBoundParamInfo>
+  getLifetimeBoundParamInfo(const Expr *Call, OriginID SrcOriginID) {
----------------
iitianpushkar wrote:

Ohh, ok. Thanks for making it clear. I will update the patch accordingly.

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


More information about the cfe-commits mailing list