[clang] [LifetimeSafety] Add support for `new`/`delete` (PR #192504)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 19 04:40:06 PDT 2026


================
@@ -47,20 +47,22 @@ class AccessPath {
     ValueDecl,
     MaterializeTemporary,
     PlaceholderParam,
-    PlaceholderThis
+    PlaceholderThis,
+    HeapAllocation,
   };
 
 private:
   Kind K;
-  const llvm::PointerUnion<const clang::ValueDecl *,
-                           const clang::MaterializeTemporaryExpr *,
-                           const ParmVarDecl *, const CXXMethodDecl *>
+  const llvm::PointerUnion<
+      const clang::ValueDecl *, const clang::MaterializeTemporaryExpr *,
+      const ParmVarDecl *, const CXXMethodDecl *, const CXXNewExpr *>
----------------
Xazax-hun wrote:

In the future, we probably also want to support other allocator functions like `malloc`. There are some attributes to mark allocator functions in Clang, we can use that to recognize them. I am not sure if it is better to have `CallExpr` added once we support malloc, or just have a catch all "Expr" in the pointer union. No strong opinion here and might not need to be addressed in this PR.

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


More information about the cfe-commits mailing list