[clang] [LifetimeSafety] Support allocating/freeing functions annotated `ownership_takes`/`ownership_returns` (PR #213439)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 3 06:22:18 PDT 2026


================
@@ -115,6 +115,15 @@ static const Loan *createLoan(FactManager &FactMgr, const CXXNewExpr *NE) {
   return FactMgr.getLoanMgr().createLoan(Path, NE);
 }
 
+/// Creates a loan for a heap allocation made by a call (e.g. a function
+/// annotated with `ownership_returns`, like `malloc`).
+/// \param CE The CallExpr that represents the allocation
+/// \return The new Loan on success, nullptr otherwise
+static const Loan *createLoan(FactManager &FactMgr, const CallExpr *CE) {
+  AccessPath Path(CE);
----------------
Xazax-hun wrote:

This is just a personal preference, but I think it is harder and harder to see at the call site what sort of AccessPath are we creating. I wonder if it would make sense to migrate to static factories like `auto path = AccessPath::newAllocation(CE)`. But this could be a follow-up. 

https://github.com/llvm/llvm-project/pull/213439


More information about the cfe-commits mailing list