[clang] [CIR][CodeGen] Support DesignatedInitUpdateExpr in constant emission (PR #194238)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Fri May 1 12:37:58 PDT 2026
================
@@ -399,9 +472,43 @@ ConstantAggregateBuilder::buildFrom(CIRGenModule &cgm, ArrayRef<Element> elems,
// If we want an array type, see if all the elements are the same type and
// appropriately spaced.
- if (mlir::isa<cir::ArrayType>(desiredTy)) {
- cgm.errorNYI("array aggregate constants");
- return {};
+ if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(desiredTy)) {
+ mlir::Type eltTy = arrTy.getElementType();
+ uint64_t numElements = arrTy.getSize();
+ CharUnits eltSize = utils.getSize(eltTy);
+
+ // Check if all elements have the correct type and are at stride offsets.
+ SmallVector<mlir::Attribute> arrayElts(numElements);
+ bool canBuildArray = true;
+
+ for (const auto &[element, offset] : elems) {
+ CharUnits relOffset = offset - startOffset;
+ if (relOffset % eltSize != CharUnits::Zero() ||
+ element.getType() != eltTy) {
+ canBuildArray = false;
+ break;
+ }
+ uint64_t idx = relOffset / eltSize;
+ if (idx >= numElements) {
+ canBuildArray = false;
+ break;
+ }
+ arrayElts[idx] = element;
+ }
+
+ if (canBuildArray) {
+ // Fill gaps with zero.
----------------
andykaylor wrote:
Can you use `emitArrayConstant` here as classic codegen does?
https://github.com/llvm/llvm-project/pull/194238
More information about the cfe-commits
mailing list