[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 18 10:57:26 PDT 2025
================
@@ -158,13 +158,56 @@ class ConstExprEmitter
// TODO(cir): this can be shared with LLVM's codegen
static QualType getNonMemoryType(CIRGenModule &cgm, QualType type) {
- if (auto at = type->getAs<AtomicType>()) {
+ if (const auto *at = type->getAs<AtomicType>()) {
return cgm.getASTContext().getQualifiedType(at->getValueType(),
type.getQualifiers());
}
return type;
}
+static mlir::Attribute
+emitArrayConstant(CIRGenModule &cgm, mlir::Type desiredType,
+ mlir::Type commonElementType, unsigned arrayBound,
+ SmallVectorImpl<mlir::TypedAttr> &elements,
+ mlir::TypedAttr filter) {
+ const auto &builder = cgm.getBuilder();
+
+ unsigned nonzeroLength = arrayBound;
+ if (elements.size() < nonzeroLength && builder.isNullValue(filter))
+ nonzeroLength = elements.size();
+
+ if (nonzeroLength == elements.size()) {
+ while (nonzeroLength > 0 &&
+ builder.isNullValue(elements[nonzeroLength - 1]))
+ --nonzeroLength;
+ }
+
+ if (nonzeroLength == 0)
+ return cir::ZeroAttr::get(builder.getContext(), desiredType);
+
+ const unsigned trailingZeroes = arrayBound - nonzeroLength;
+ if (trailingZeroes >= 8) {
+ if (elements.size() < nonzeroLength)
+ cgm.errorNYI("missing initializer for non-zero element");
+ } else if (elements.size() != arrayBound) {
+ elements.resize(arrayBound, filter);
+
+ if (filter.getType() != commonElementType)
+ cgm.errorNYI(
----------------
AmrDeveloper wrote:
My point is that it's will not be assert or error after we support StructType
https://github.com/llvm/llvm-project/pull/131657
More information about the cfe-commits
mailing list