Skip to content

Commit dcab7ba

Browse files
committed
Addressing nit comments
1 parent 84d6371 commit dcab7ba

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/include/clang/Analysis/Analyses/LifetimeSafety/LifetimeSafety.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class LifetimeSafetyReporter {
4848
SourceLocation ExpiryLoc,
4949
Confidence Confidence) {}
5050

51+
// Suggests lifetime bound annotations for function paramters
5152
virtual void suggestAnnotation(const ParmVarDecl *PVD,
5253
const Expr *EscapeExpr) {}
5354
};

clang/include/clang/Analysis/Analyses/LifetimeSafety/Loans.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ struct AccessPath {
3434
AccessPath(const clang::ValueDecl *D) : D(D) {}
3535
};
3636

37-
/// An abstract base class for a single borrow, or "Loan".
37+
/// An abstract base class for a single "Loan" which represents a lifetime
38+
/// dependency.
3839
class Loan {
3940
/// TODO: Represent opaque loans.
4041
/// TODO: Represent nullptr: loans to no path. Accessing it UB! Currently it
@@ -62,10 +63,11 @@ class Loan {
6263
const LoanID ID;
6364
};
6465

65-
/// Information about a single borrow, or "Loan". A loan is created when a
66+
/// Information about a single borrow loan. A borrow loan is created when a
6667
/// reference or pointer is created.
6768
class BorrowLoan : public Loan {
6869
AccessPath Path;
70+
/// The expression that creates the loan, e.g., &x.
6971
const Expr *IssueExpr;
7072

7173
public:
@@ -117,6 +119,10 @@ class LoanManager {
117119

118120
template <typename LoanType, typename... Args>
119121
LoanType *createLoan(Args &&...args) {
122+
static_assert(
123+
std::is_same_v<LoanType, BorrowLoan> ||
124+
std::is_same_v<LoanType, PlaceholderLoan>,
125+
"createLoan can only be used with BorrowLoan or PlaceholderLoan");
120126
void *Mem = LoanAllocator.Allocate<LoanType>();
121127
auto *NewLoan =
122128
new (Mem) LoanType(getNextLoanID(), std::forward<Args>(args)...);

0 commit comments

Comments
 (0)