Skip to content

Commit e1aaaf5

Browse files
committed
Address some review feedback
1 parent 6cb9af0 commit e1aaaf5

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,14 @@ def CIR_ArrayCtor : CIR_ArrayInitDestroy<"array.ctor"> {
22612261
Initialize each array element using the same C++ constructor. This
22622262
operation has one region, with one single block. The block has an
22632263
incoming argument for the current array index to initialize.
2264+
2265+
```mlir
2266+
cir.array.ctor(%0 : !cir.ptr<!cir.array<!rec_S x 42>>) {
2267+
^bb0(%arg0: !cir.ptr<!rec_S>):
2268+
cir.call @_ZN1SC1Ev(%arg0) : (!cir.ptr<!rec_S>) -> ()
2269+
cir.yield
2270+
}
2271+
```
22642272
}];
22652273
}
22662274

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ struct MissingFeatures {
254254
static bool dtorCleanups() { return false; }
255255
static bool vtableInitialization() { return false; }
256256
static bool msvcBuiltins() { return false; }
257+
static bool vlas() { return false; }
257258

258259
// Missing types
259260
static bool dataMemberType() { return false; }

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
355355
// Just skip out if the constant count is zero.
356356
if (constIntAttr && constIntAttr.getUInt() == 0)
357357
return;
358-
// Otherwise, emit the check.
359358
} else {
359+
// Otherwise, emit the check.
360360
cgm.errorNYI(e->getSourceRange(), "dynamic-length array expression");
361361
}
362362

@@ -399,7 +399,8 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
399399
}
400400

401401
// Emit the constructor call that will execute for every array element.
402-
mlir::Value arrayOp = builder.createPtrBitcast(arrayBase.getPointer(), arrayTy);
402+
mlir::Value arrayOp =
403+
builder.createPtrBitcast(arrayBase.getPointer(), arrayTy);
403404
builder.create<cir::ArrayCtor>(
404405
*currSrcLoc, arrayOp, [&](mlir::OpBuilder &b, mlir::Location loc) {
405406
auto arg = b.getInsertionBlock()->addArgument(ptrToElmType, loc);

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ CIRGenFunction::emitArrayLength(const clang::ArrayType *origArrayType,
818818
// If it's a VLA, we have to load the stored size. Note that
819819
// this is the size of the VLA in bytes, not its size in elements.
820820
if (isa<VariableArrayType>(arrayType)) {
821+
assert(cir::MissingFeatures::vlas());
821822
cgm.errorNYI(*currSrcLoc, "VLAs");
822823
return builder.getConstInt(*currSrcLoc, SizeTy, 0);
823824
}

clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang/CIR/Dialect/IR/CIRDialect.h"
1414
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
1515
#include "clang/CIR/Dialect/Passes.h"
16+
#include "clang/CIR/MissingFeatures.h"
1617

1718
#include <memory>
1819

@@ -147,6 +148,7 @@ void LoweringPreparePass::lowerArrayCtor(cir::ArrayCtor op) {
147148
builder.setInsertionPointAfter(op.getOperation());
148149

149150
mlir::Type eltTy = op->getRegion(0).getArgument(0).getType();
151+
assert(!cir::MissingFeatures::vlas());
150152
auto arrayLen =
151153
mlir::cast<cir::ArrayType>(op.getAddr().getType().getPointee()).getSize();
152154
lowerArrayDtorCtorIntoLoop(builder, astCtx, op, eltTy, op.getAddr(),

clang/test/CIR/CodeGen/array-ctor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ void foo() {
6868
// OGCG: br i1 %[[DONE]], label %[[EXIT:.*]], label %[[LOOP]]
6969
// OGCG: [[EXIT]]:
7070
// OGCG: ret void
71+
72+
void zero_sized() {
73+
int s[0];
74+
}
75+
76+
// CIR: cir.func dso_local @_Z10zero_sizedv()
77+
// CIR-NOT: cir.do
78+
// CIR: cir.return

0 commit comments

Comments
 (0)