@@ -42,10 +42,20 @@ enum class SuggestionScope {
4242 IntraTU // For suggestions on definitions local to a Translation Unit.
4343};
4444
45- class LifetimeSafetyReporter {
45+ // / Abstract interface for operations requiring Sema access.
46+ // /
47+ // / This class exists to break a circular dependency: the LifetimeSafety
48+ // / analysis target cannot directly depend on clangSema (which would create the
49+ // / cycle: clangSema -> clangAnalysis -> clangAnalysisLifetimeSafety ->
50+ // / clangSema).
51+ // /
52+ // / Instead, this interface is implemented in AnalysisBasedWarnings.cpp (part of
53+ // / clangSema), allowing the analysis to report diagnostics and modify the AST
54+ // / through Sema without introducing a circular dependency.
55+ class LifetimeSafetySemaHelper {
4656public:
47- LifetimeSafetyReporter () = default ;
48- virtual ~LifetimeSafetyReporter () = default ;
57+ LifetimeSafetySemaHelper () = default ;
58+ virtual ~LifetimeSafetySemaHelper () = default ;
4959
5060 virtual void reportUseAfterFree (const Expr *IssueExpr, const Expr *UseExpr,
5161 SourceLocation FreeLoc,
@@ -56,15 +66,24 @@ class LifetimeSafetyReporter {
5666 SourceLocation ExpiryLoc,
5767 Confidence Confidence) {}
5868
59- // Suggests lifetime bound annotations for function paramters
60- virtual void suggestAnnotation (SuggestionScope Scope,
61- const ParmVarDecl *ParmToAnnotate,
62- const Expr *EscapeExpr) {}
69+ // Suggests lifetime bound annotations for function paramters.
70+ virtual void suggestLifetimeboundToParmVar (SuggestionScope Scope,
71+ const ParmVarDecl *ParmToAnnotate,
72+ const Expr *EscapeExpr) {}
73+
74+ // Suggests lifetime bound annotations for implicit this.
75+ virtual void suggestLifetimeboundToImplicitThis (SuggestionScope Scope,
76+ const CXXMethodDecl *MD,
77+ const Expr *EscapeExpr) {}
78+
79+ // Adds inferred lifetime bound attribute for implicit this to its
80+ // TypeSourceInfo.
81+ virtual void addLifetimeBoundToImplicitThis (const CXXMethodDecl *MD) {}
6382};
6483
6584// / The main entry point for the analysis.
6685void runLifetimeSafetyAnalysis (AnalysisDeclContext &AC,
67- LifetimeSafetyReporter *Reporter ,
86+ LifetimeSafetySemaHelper *SemaHelper ,
6887 LifetimeSafetyStats &Stats, bool CollectStats);
6988
7089namespace internal {
@@ -85,7 +104,7 @@ struct LifetimeFactory {
85104class LifetimeSafetyAnalysis {
86105public:
87106 LifetimeSafetyAnalysis (AnalysisDeclContext &AC,
88- LifetimeSafetyReporter *Reporter );
107+ LifetimeSafetySemaHelper *SemaHelper );
89108
90109 void run ();
91110
@@ -98,7 +117,7 @@ class LifetimeSafetyAnalysis {
98117
99118private:
100119 AnalysisDeclContext ∾
101- LifetimeSafetyReporter *Reporter ;
120+ LifetimeSafetySemaHelper *SemaHelper ;
102121 LifetimeFactory Factory;
103122 std::unique_ptr<FactManager> FactMgr;
104123 std::unique_ptr<LiveOriginsAnalysis> LiveOrigins;
0 commit comments