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)
3636};
3737
38+ enum class LivenessKind : uint8_t {
39+ Dead, // Not alive
40+ Maybe, // Live on some path but not all paths (may-be-live)
41+ Must // Live on all paths (must-be-live)
42+ };
43+
3844class LifetimeSafetyReporter {
3945public:
4046 LifetimeSafetyReporter () = default ;
@@ -55,6 +61,7 @@ class Fact;
5561class FactManager ;
5662class LoanPropagationAnalysis ;
5763class ExpiredLoansAnalysis ;
64+ class LiveOriginAnalysis ;
5865struct LifetimeFactory ;
5966
6067// / A generic, type-safe wrapper for an ID, distinguished by its `Tag` type.
@@ -89,6 +96,7 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, OriginID ID) {
8996// TODO(opt): Consider using a bitset to represent the set of loans.
9097using LoanSet = llvm::ImmutableSet<LoanID>;
9198using OriginSet = llvm::ImmutableSet<OriginID>;
99+ using OriginLoanMap = llvm::ImmutableMap<OriginID, LoanSet>;
92100
93101// / A `ProgramPoint` identifies a location in the CFG by pointing to a specific
94102// / `Fact`. identified by a lifetime-related event (`Fact`).
@@ -110,8 +118,16 @@ class LifetimeSafetyAnalysis {
110118 // / Returns the set of loans an origin holds at a specific program point.
111119 LoanSet getLoansAtPoint (OriginID OID, ProgramPoint PP) const ;
112120
113- // / Returns the set of loans that have expired at a specific program point.
114- std::vector<LoanID> getExpiredLoansAtPoint (ProgramPoint PP) const ;
121+ // / Returns the set of origins that are live at a specific program point,
122+ // / along with the confidence level of their liveness.
123+ // /
124+ // / An origin is considered live if there are potential future uses of that
125+ // / origin after the given program point. The confidence level indicates
126+ // / whether the origin is definitely live (Definite) due to being domintated
127+ // / by a set of uses or only possibly live (Maybe) only on some but not all
128+ // / control flow paths.
129+ std::vector<std::pair<OriginID, LivenessKind>>
130+ getLiveOriginsAtPoint (ProgramPoint PP) const ;
115131
116132 // / Finds the OriginID for a given declaration.
117133 // / Returns a null optional if not found.
@@ -138,7 +154,7 @@ class LifetimeSafetyAnalysis {
138154 std::unique_ptr<LifetimeFactory> Factory;
139155 std::unique_ptr<FactManager> FactMgr;
140156 std::unique_ptr<LoanPropagationAnalysis> LoanPropagation;
141- std::unique_ptr<ExpiredLoansAnalysis> ExpiredLoans ;
157+ std::unique_ptr<LiveOriginAnalysis> LiveOrigins ;
142158};
143159} // namespace internal
144160} // namespace clang::lifetimes
0 commit comments