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

via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 19 12:26:47 PDT 2026


================
@@ -615,6 +623,37 @@ void FactsGenerator::VisitArraySubscriptExpr(const ArraySubscriptExpr *ASE) {
       Dst->getOuterOriginID(), Src->getOuterOriginID(), /*Kill=*/true));
 }
 
+void FactsGenerator::VisitCXXNewExpr(const CXXNewExpr *NE) {
+  OriginList *NewList = getOriginsList(*NE);
+
+  const Loan *L = createLoan(FactMgr, NE);
+  CurrentBlockFacts.push_back(
+      FactMgr.createFact<IssueFact>(L->getID(), NewList->getOuterOriginID()));
+
+  NewList = NewList->peelOuterOrigin();
+
+  if (!NewList)
+    return;
+
+  if (auto *CE = NE->getConstructExpr(); CE) {
+    if (OriginList *ArgList = getOriginsList(*CE); ArgList)
+      flow(NewList, ArgList, true);
+  } else if (const Expr *E = NE->getInitializer(); E) {
+    if (const auto *ILE = dyn_cast<InitListExpr>(E); NE->isArray() && ILE) {
+      if (OriginList *InitList = getOriginsList(*ILE); InitList)
+        flow(NewList, InitList, true);
+    } else if (OriginList *ArgList = getOriginsList(*E); ArgList) {
+      flow(NewList, ArgList, true);
+    }
----------------
NeKon69 wrote:

Well if I do this then `pointer_array_field_sensitivity` and `new_pointer_array_from_dead_objects` both crash. I will try to investigate this.

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


More information about the cfe-commits mailing list