[clang] [CIR] Implement support for delete after new in a conditional branch (PR #192544)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 17 16:58:43 PDT 2026
================
@@ -901,17 +895,60 @@ static void enterNewDeleteCleanup(CIRGenFunction &cgf, const CXXNewExpr *e,
typedef CallDeleteDuringNew<DirectCleanupTraits> DirectCleanup;
assert(!cir::MissingFeatures::typeAwareAllocation());
- cgf.ehStack.pushCleanupWithExtra<DirectCleanup>(
+ DirectCleanup *cleanup = cgf.ehStack.pushCleanupWithExtra<DirectCleanup>(
EHCleanup, e->getNumPlacementArgs(), e->getOperatorDelete(),
newPtr.getPointer(), allocSize, e->implicitAllocationParameters(),
- allocAlign, &newArgs, numNonPlacementArgs, &cgf,
- cgf.getLoc(e->getSourceRange()));
+ allocAlign);
+ for (auto i : llvm::seq<unsigned>(0, e->getNumPlacementArgs())) {
+ const CallArg &arg = newArgs[i + numNonPlacementArgs];
+ cleanup->setPlacementArg(
+ i, arg.getRValue(cgf, cgf.getLoc(e->getSourceRange())), arg.ty);
+ }
return;
}
- cgf.cgm.errorNYI(e->getSourceRange(),
- "enterNewDeleteCleanup: conditional branch");
+ // Otherwise, we need to save all this stuff.
+ auto saveValue = [&](mlir::Value value) -> mlir::Value {
----------------
andykaylor wrote:
This is a much simpler implementation. It doesn't attempt to look for cases where the values don't need to be saved, but the optimizer should handle that. In particular, you'll see in the CIR checks for the test that we spill the size even when it's a constant, but that gets resolved during lowering to LLVM IR.
https://github.com/llvm/llvm-project/pull/192544
More information about the cfe-commits
mailing list