[clang] [LifetimeSafety] Add placement new support (PR #194030)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 25 11:04:07 PDT 2026


================
@@ -626,9 +632,31 @@ void FactsGenerator::VisitArraySubscriptExpr(const ArraySubscriptExpr *ASE) {
 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()));
+  // Check if we have a placement new where the second argument is void*, to
+  // avoid flowing from non-pointer parameters, such as std::nothrow.
+  // And that the placement parameter num is 1,
+  // that is to mostly limit to standard library placement new.
+  if (NE->getNumPlacementArgs() == 1) {
+    if (const auto *Arg = NE->getOperatorNew()
+                              ->getParamDecl(1)
+                              ->getType()
+                              ->getAs<PointerType>();
+        Arg && Arg->isVoidPointerType()) {
+      const Expr *PlacementArg = NE->getPlacementArg(0)->IgnoreImpCasts();
----------------
usx95 wrote:

Can you attach the AST of this expression here in the thread.  
Please also document each of the flows, casts, peelOuterOrigin and the likes in this method. Currently it is hard to follow the intention here.

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


More information about the cfe-commits mailing list