[clang] Propagate lifetimebound from formal parameters to those in the canonical declaration and use that for analysis (PR #107627)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 13 09:23:43 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>()) {
----------------
higher-performance wrote:
I just tried this but I realized it doesn't work because we want backward propagation to the canonical declaration (since that's what we'll use), rather than forward propagation to the latest one. Unless you're suggesting I change that logic?
https://github.com/llvm/llvm-project/pull/107627
More information about the cfe-commits
mailing list