29
29
namespace clang ::lifetimes {
30
30
31
31
// / Enum to track the confidence level of a potential error.
32
- enum class Confidence {
32
+ enum class Confidence : uint8_t {
33
33
None,
34
34
Maybe, // Reported as a potential error (-Wlifetime-safety-strict)
35
35
Definite // Reported as a definite error (-Wlifetime-safety-permissive)
36
36
};
37
37
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
+
38
44
class LifetimeSafetyReporter {
39
45
public:
40
46
LifetimeSafetyReporter () = default ;
@@ -55,6 +61,7 @@ class Fact;
55
61
class FactManager ;
56
62
class LoanPropagationAnalysis ;
57
63
class ExpiredLoansAnalysis ;
64
+ class LiveOriginAnalysis ;
58
65
struct LifetimeFactory ;
59
66
60
67
// / 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) {
89
96
// TODO(opt): Consider using a bitset to represent the set of loans.
90
97
using LoanSet = llvm::ImmutableSet<LoanID>;
91
98
using OriginSet = llvm::ImmutableSet<OriginID>;
99
+ using OriginLoanMap = llvm::ImmutableMap<OriginID, LoanSet>;
92
100
93
101
// / A `ProgramPoint` identifies a location in the CFG by pointing to a specific
94
102
// / `Fact`. identified by a lifetime-related event (`Fact`).
@@ -110,8 +118,16 @@ class LifetimeSafetyAnalysis {
110
118
// / Returns the set of loans an origin holds at a specific program point.
111
119
LoanSet getLoansAtPoint (OriginID OID, ProgramPoint PP) const ;
112
120
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 ;
115
131
116
132
// / Finds the OriginID for a given declaration.
117
133
// / Returns a null optional if not found.
@@ -138,7 +154,7 @@ class LifetimeSafetyAnalysis {
138
154
std::unique_ptr<LifetimeFactory> Factory;
139
155
std::unique_ptr<FactManager> FactMgr;
140
156
std::unique_ptr<LoanPropagationAnalysis> LoanPropagation;
141
- std::unique_ptr<ExpiredLoansAnalysis> ExpiredLoans ;
157
+ std::unique_ptr<LiveOriginAnalysis> LiveOrigins ;
142
158
};
143
159
} // namespace internal
144
160
} // namespace clang::lifetimes
0 commit comments