[clang] [CIR] Add support for array cleanups (PR #150499)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 25 06:21:16 PDT 2025
================
@@ -213,15 +215,23 @@ static void lowerArrayDtorCtorIntoLoop(cir::CIRBaseBuilderTy &builder,
op->walk([&](cir::CallOp c) { ctorCall = c; });
assert(ctorCall && "expected ctor call");
- auto one = builder.create<cir::ConstantOp>(
- loc, ptrDiffTy, cir::IntAttr::get(ptrDiffTy, 1));
-
- ctorCall->moveAfter(one);
- ctorCall->setOperand(0, currentElement);
-
- // Advance pointer and store them to temporary variable
- auto nextElement =
- builder.create<cir::PtrStrideOp>(loc, eltTy, currentElement, one);
+ // Array elements get constructed in order but destructed in reverse.
+ cir::PtrStrideOp nextElement;
+ if (isCtor) {
+ mlir::Value stride = builder.getUnsignedInt(loc, 1, sizeTypeSize);
+ ctorCall->moveBefore(stride.getDefiningOp());
+ ctorCall->setOperand(0, currentElement);
+ nextElement = builder.create<cir::PtrStrideOp>(
+ loc, eltTy, currentElement, stride);
----------------
xlauko wrote:
```suggestion
nextElement = cir::PtrStrideOp::create(
builder, loc, eltTy, currentElement, stride);
```
https://github.com/llvm/llvm-project/pull/150499
More information about the cfe-commits
mailing list