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

via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 25 10:36:32 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();
----------------
NeKon69 wrote:

If we don't ignore implicit casts then we only get OriginList of depth 1 which comes from cast to void*

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


More information about the cfe-commits mailing list