Skip to content

Commit 978303c

Browse files
committed
Address code review comments
1 parent 4c97120 commit 978303c

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
4545
return false;
4646
}
4747

48-
// Return true if this is the null value
48+
// Return true if the value is a null constant such as null pointer, (+0.0)
49+
// for floating-point or zero initializer
4950
bool isNullValue(mlir::Attribute attr) const {
5051
if (mlir::isa<cir::ZeroAttr>(attr))
5152
return true;

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,24 @@ emitArrayConstant(CIRGenModule &cgm, mlir::Type desiredType,
195195
elements.resize(arrayBound, filler);
196196

197197
if (filler.getType() != commonElementType)
198-
cgm.errorNYI(
199-
"array filter type should always be the same as element type");
198+
commonElementType = {};
200199
}
201200

202-
SmallVector<mlir::Attribute, 4> eles;
203-
eles.reserve(elements.size());
201+
if (commonElementType) {
202+
SmallVector<mlir::Attribute, 4> eles;
203+
eles.reserve(elements.size());
204204

205-
for (const auto &element : elements)
206-
eles.push_back(element);
205+
for (const auto &element : elements)
206+
eles.push_back(element);
207207

208-
return cir::ConstArrayAttr::get(
209-
cir::ArrayType::get(builder.getContext(), commonElementType, arrayBound),
210-
mlir::ArrayAttr::get(builder.getContext(), eles));
208+
return cir::ConstArrayAttr::get(
209+
cir::ArrayType::get(builder.getContext(), commonElementType,
210+
arrayBound),
211+
mlir::ArrayAttr::get(builder.getContext(), eles));
212+
}
213+
214+
cgm.errorNYI("array with different type elements");
215+
return {};
211216
}
212217

213218
//===----------------------------------------------------------------------===//
@@ -354,9 +359,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
354359
if (i == 0)
355360
commonElementType = elementTyped.getType();
356361
else if (elementTyped.getType() != commonElementType) {
357-
cgm.errorNYI("ConstExprEmitter::tryEmitPrivate Array without common "
358-
"element type");
359-
return {};
362+
commonElementType = {};
360363
}
361364

362365
elements.push_back(elementTyped);

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,12 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::FPAttr fltAttr) {
259259

260260
// ConstArrayAttr visitor
261261
mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
262-
auto llvmTy = converter->convertType(attr.getType());
263-
auto loc = parentOp->getLoc();
262+
mlir::Type llvmTy = converter->convertType(attr.getType());
263+
mlir::Location loc = parentOp->getLoc();
264264
mlir::Value result;
265265

266266
if (auto zeros = attr.getTrailingZerosNum()) {
267-
auto arrayTy = attr.getType();
267+
mlir::Type arrayTy = attr.getType();
268268
result = rewriter.create<mlir::LLVM::ZeroOp>(
269269
loc, converter->convertType(arrayTy));
270270
} else {

0 commit comments

Comments
 (0)