2929namespace clang ::lifetimes {
3030
3131// / Enum to track the confidence level of a potential error.
32- enum class Confidence {
32+ enum class Confidence : uint8_t {
3333 None,
3434 Maybe, // Reported as a potential error (-Wlifetime-safety-strict)
3535 Definite // Reported as a definite error (-Wlifetime-safety-permissive)
@@ -55,6 +55,7 @@ class Fact;
5555class FactManager ;
5656class LoanPropagationAnalysis ;
5757class ExpiredLoansAnalysis ;
58+ class LiveOriginAnalysis ;
5859struct LifetimeFactory ;
5960
6061// / A generic, type-safe wrapper for an ID, distinguished by its `Tag` type.
@@ -89,6 +90,7 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, OriginID ID) {
8990// TODO(opt): Consider using a bitset to represent the set of loans.
9091using LoanSet = llvm::ImmutableSet<LoanID>;
9192using OriginSet = llvm::ImmutableSet<OriginID>;
93+ using OriginLoanMap = llvm::ImmutableMap<OriginID, LoanSet>;
9294
9395// / A `ProgramPoint` identifies a location in the CFG by pointing to a specific
9496// / `Fact`. identified by a lifetime-related event (`Fact`).
@@ -110,8 +112,16 @@ class LifetimeSafetyAnalysis {
110112 // / Returns the set of loans an origin holds at a specific program point.
111113 LoanSet getLoansAtPoint (OriginID OID, ProgramPoint PP) const ;
112114
113- // / Returns the set of loans that have expired at a specific program point.
114- std::vector<LoanID> getExpiredLoansAtPoint (ProgramPoint PP) const ;
115+ // / Returns the set of origins that are live at a specific program point,
116+ // / along with the confidence level of their liveness.
117+ // /
118+ // / An origin is considered live if there are potential future uses of that
119+ // / origin after the given program point. The confidence level indicates
120+ // / whether the origin is definitely live (Definite) due to being domintated
121+ // / by a set of uses or only possibly live (Maybe) only on some but not all
122+ // / control flow paths.
123+ std::vector<std::pair<OriginID, Confidence>>
124+ getLiveOriginsAtPoint (ProgramPoint PP) const ;
115125
116126 // / Finds the OriginID for a given declaration.
117127 // / Returns a null optional if not found.
@@ -138,7 +148,7 @@ class LifetimeSafetyAnalysis {
138148 std::unique_ptr<LifetimeFactory> Factory;
139149 std::unique_ptr<FactManager> FactMgr;
140150 std::unique_ptr<LoanPropagationAnalysis> LoanPropagation;
141- std::unique_ptr<ExpiredLoansAnalysis> ExpiredLoans ;
151+ std::unique_ptr<LiveOriginAnalysis> LiveOrigins ;
142152};
143153} // namespace internal
144154} // namespace clang::lifetimes
0 commit comments