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

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 07:13:10 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();
----------------
Xazax-hun wrote:

Intersting, that almost sounds like we are handling those casts incorrectly. I'd expect the lvalue to rvalue cast to strip the origin from the outer pointer, so we only get the origins for the view underneath. 

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


More information about the cfe-commits mailing list