[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:17 PDT 2025
================
@@ -658,10 +693,38 @@ void CIRGenFunction::emitNullabilityCheck(LValue lhs, mlir::Value rhs,
/// elements
void CIRGenFunction::emitDestroy(Address addr, QualType type,
Destroyer *destroyer) {
- if (getContext().getAsArrayType(type))
- cgm.errorNYI("emitDestroy: array type");
+ const ArrayType *arrayType = getContext().getAsArrayType(type);
+ if (!arrayType)
+ return destroyer(*this, addr, type);
+
+ mlir::Value length = emitArrayLength(arrayType, type, addr);
+
+ CharUnits elementAlign = addr.getAlignment().alignmentOfArrayElement(
+ getContext().getTypeSizeInChars(type));
+
+ // Normally we have to check whether the array is zero-length.
+ bool checkZeroLength = true;
+
+ // But if the array length is constant, we can suppress that.
+ auto constantCount = dyn_cast<cir::ConstantOp>(length.getDefiningOp());
----------------
xlauko wrote:
```suggestion
auto constantCount = length.getDefiningOp<cir::ConstantOp>();
```
https://github.com/llvm/llvm-project/pull/150499
More information about the cfe-commits
mailing list