[clang] [Lifetime Safety] Highlight lifetimebound calls in alias chain diagnostics (PR #206337)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 7 04:17:55 PDT 2026
================
@@ -664,20 +665,44 @@ class LifetimeSafetySemaHelperImpl : public LifetimeSafetySemaHelper {
return CurrExpr->getSourceRange() != LastExpr->getSourceRange();
}
- void reportAliasingChain(llvm::ArrayRef<const Expr *> OriginExprChain) {
+ void reportAliasingChain(llvm::ArrayRef<AliasChainEntry> OriginExprChain) {
if (OriginExprChain.empty())
return;
- const Expr *LastExpr = OriginExprChain.back();
+ AliasChainEntry Last = OriginExprChain.back();
+ const Expr *LastExpr = Last.E;
std::string IssueStr = getDiagSubjectDescription(LastExpr);
- for (const Expr *CurrExpr : reverse(OriginExprChain.drop_back())) {
- if (!shouldShowInAliasChain(CurrExpr, LastExpr))
+ for (AliasChainEntry Curr : reverse(OriginExprChain.drop_back())) {
+ const Expr *CurrExpr = Curr.E;
+ if (!shouldShowInAliasChain(CurrExpr, LastExpr)) {
+ if (!Last.LifetimeBound && Curr.LifetimeBound)
+ Last.LifetimeBound = Curr.LifetimeBound;
continue;
- S.Diag(CurrExpr->getBeginLoc(),
- diag::note_lifetime_safety_aliases_storage)
- << CurrExpr->getSourceRange() << getDiagSubjectDescription(CurrExpr)
- << IssueStr;
+ }
+ if (Last.LifetimeBound) {
+ std::string LifetimeBoundSubject;
+ if (Last.LifetimeBound->IsImplicitObject) {
+ LifetimeBoundSubject = "the implicit object parameter";
----------------
Xazax-hun wrote:
I wonder if these texts could be part of the diagnostic test instead and we could use `select` and similar to get the right variant.
https://github.com/llvm/llvm-project/pull/206337
More information about the cfe-commits
mailing list