[clang] [LifetimeSafety] Add suggestion and inference for implicit this (PR #176703)
Kashika Akhouri via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 22 23:12:43 PST 2026
================
@@ -60,6 +60,14 @@ class LifetimeSafetyReporter {
virtual void suggestAnnotation(SuggestionScope Scope,
const ParmVarDecl *ParmToAnnotate,
const Expr *EscapeExpr) {}
+
+ // Suggests lifetime bound annotations for implicit this
+ virtual void suggestAnnotation(SuggestionScope Scope, const CXXMethodDecl *MD,
+ const Expr *EscapeExpr) {}
+
+ // Adds inferred lifetime bound attribute for implicit this to its
+ // TypeSourceInfo
+ virtual void addLifetimeBoundToImplicitThis(const CXXMethodDecl *MD) {}
----------------
kashika0112 wrote:
The implementation of addLifetimeBoundToImplicitThis requires modifying the TSI, which is done using the TypeLocBuilder utility. TypeLocBuilder is an internal header within libSema and is not exposed to libAnalysis. I added this function in LifetimeSafetyReporter as it already holds a reference to Sema.
One way I can think of is move the actual implementation of this TSI transformation to a static helper in SemaDecl.cpp or keep it as a private helper in AnalysisBasedWarnings.cpp. Let me know which is more suitable here.
https://github.com/llvm/llvm-project/pull/176703
More information about the cfe-commits
mailing list