[clang] Propagate lifetimebound from formal parameters to those in the canonical declaration and use that for analysis (PR #107627)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 13 07:55:15 PDT 2024


================
@@ -266,6 +262,20 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
               LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation()));
       }
     }
+  } else if (auto *CanonDecl = FD->getCanonicalDecl(); FD != CanonDecl) {
+    // Propagate the lifetimebound attribute from parameters to the canonical
+    // declaration.
+    // Note that this doesn't include the implicit 'this' parameter, as the
+    // attribute is applied to the function type in that case.
+    const unsigned int NP = std::min(NumParams, CanonDecl->getNumParams());
+    for (unsigned int I = 0; I < NP; ++I) {
+      auto *CanonParam = CanonDecl->getParamDecl(I);
+      if (!CanonParam->hasAttr<LifetimeBoundAttr>() &&
+          FD->getParamDecl(I)->hasAttr<LifetimeBoundAttr>()) {
----------------
ilya-biryukov wrote:

I'll probably have more comments, but just wanted to point out that a much more appropriate place for this logic would be `Sema::mergeDeclAttributes` and the `mergeParamDeclAttributes` helper function, in particular.


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


More information about the cfe-commits mailing list