[clang] [CIR] Add support for null checks with operator delete (PR #185987)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 12 06:09:21 PDT 2026
================
@@ -1201,10 +1196,21 @@ void CIRGenFunction::emitCXXDeleteExpr(const CXXDeleteExpr *e) {
// unconditionally perform the operator delete call in that case. For now, we
// assume that deleted pointers are null rarely enough that it's better to
// keep the branch. This might be worth revisiting for a -O0 code size win.
- //
- // CIR note: emit the code size friendly by default for now, such as mentioned
- // in `emitObjectDelete`.
assert(!cir::MissingFeatures::emitNullCheckForDeleteCalls());
+ cir::YieldOp thenYield;
+ mlir::Value notNull = builder.createPtrNotNull(ptr.getPointer());
+ cir::IfOp::create(builder, getLoc(e->getExprLoc()), notNull,
+ /*withElseRegion=*/false,
+ /*thenBuilder=*/
+ [&](mlir::OpBuilder &b, mlir::Location loc) {
+ thenYield = builder.createYield(loc);
+ });
+
+ // Emit the rest of the CIR inside the if-op's then region, but restore the
+ // insertion point to the point after the if when this function returns.
+ mlir::OpBuilder::InsertionGuard guard(builder);
----------------
erichkeane wrote:
Ah, huh.... I kinda hate those too :) Less motivated to change here then, I'd suspect it would be cleaner/less awkward to change them all, but that can be done another day.
https://github.com/llvm/llvm-project/pull/185987
More information about the cfe-commits
mailing list