[clang] [LifetimeSafety] Introduce AccessPath-based expiry (PR #187708)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 20 07:28:50 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang/include/clang/Analysis/Analyses/LifetimeSafety/Facts.h clang/include/clang/Analysis/Analyses/LifetimeSafety/Loans.h clang/lib/Analysis/LifetimeSafety/Checker.cpp clang/lib/Analysis/LifetimeSafety/Facts.cpp clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp clang/lib/Analysis/LifetimeSafety/Loans.cpp clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp clang/test/Sema/warn-lifetime-safety-dataflow.cpp clang/test/Sema/warn-lifetime-safety.cpp clang/unittests/Analysis/LifetimeSafetyTest.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Analysis/Analyses/LifetimeSafety/Loans.h b/clang/include/clang/Analysis/Analyses/LifetimeSafety/Loans.h
index bb3e2cd90..b1a2241f2 100644
--- a/clang/include/clang/Analysis/Analyses/LifetimeSafety/Loans.h
+++ b/clang/include/clang/Analysis/Analyses/LifetimeSafety/Loans.h
@@ -31,8 +31,9 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, LoanID ID) {
/// function parameter or the implicit 'this' object of an instance method.
/// Placeholder paths never expire within the function scope, as they represent
/// storage from the caller's scope.
-class PlaceholderBase {
+class PlaceholderBase {
llvm::PointerUnion<const ParmVarDecl *, const CXXMethodDecl *> ParamOrMethod;
+
public:
PlaceholderBase(const ParmVarDecl *PVD) : ParamOrMethod(PVD) {}
PlaceholderBase(const CXXMethodDecl *MD) : ParamOrMethod(MD) {}
@@ -66,15 +67,14 @@ class AccessPath {
const clang::MaterializeTemporaryExpr *,
const PlaceholderBase *>
Base;
+
public:
AccessPath(const clang::ValueDecl *D) : Base(D) {}
AccessPath(const clang::MaterializeTemporaryExpr *MTE) : Base(MTE) {}
AccessPath(const PlaceholderBase *PB) : Base(PB) {}
/// Creates an extended access path by appending a path element.
/// Example: AccessPath(x_path, field) creates path to `x.field`.
- AccessPath(const AccessPath &Other)
- : Base(Other.Base){
- }
+ AccessPath(const AccessPath &Other) : Base(Other.Base) {}
const clang::ValueDecl *getAsValueDecl() const {
return Base.dyn_cast<const clang::ValueDecl *>();
}
@@ -84,12 +84,8 @@ public:
const PlaceholderBase *getAsPlaceholderBase() const {
return Base.dyn_cast<const PlaceholderBase *>();
}
- bool operator==(const AccessPath &RHS) const {
- return Base == RHS.Base;
- }
- bool operator!=(const AccessPath &RHS) const {
- return !(Base == RHS.Base);
- }
+ bool operator==(const AccessPath &RHS) const { return Base == RHS.Base; }
+ bool operator!=(const AccessPath &RHS) const { return !(Base == RHS.Base); }
void dump(llvm::raw_ostream &OS) const;
};
@@ -110,6 +106,7 @@ class Loan {
/// The expression that creates the loan, e.g., &x. Null for placeholder
/// loans.
const Expr *IssueExpr;
+
public:
Loan(LoanID ID, AccessPath Path, const Expr *IssueExpr = nullptr)
: ID(ID), Path(Path), IssueExpr(IssueExpr) {}
@@ -124,12 +121,11 @@ class LoanManager {
public:
LoanManager() = default;
- Loan *createLoan(AccessPath Path, const Expr *IssueExpr = nullptr) {
+ Loan *createLoan(AccessPath Path, const Expr *IssueExpr = nullptr) {
void *Mem = LoanAllocator.Allocate<Loan>();
auto *NewLoan = new (Mem) Loan(getNextLoanID(), Path, IssueExpr);
AllLoans.push_back(NewLoan);
return NewLoan;
-
}
const Loan *getLoan(LoanID ID) const {
@@ -150,7 +146,7 @@ private:
/// TODO(opt): Profile and evaluate the usefullness of small buffer
/// optimisation.
llvm::SmallVector<const Loan *> AllLoans;
- llvm::DenseMap<const Decl*, const PlaceholderBase*> PlaceholderBases;
+ llvm::DenseMap<const Decl *, const PlaceholderBase *> PlaceholderBases;
llvm::BumpPtrAllocator LoanAllocator;
};
} // namespace clang::lifetimes::internal
``````````
</details>
https://github.com/llvm/llvm-project/pull/187708
More information about the cfe-commits
mailing list