Skip to content

Commit d013307

Browse files
committed
Address some review feedback
1 parent 7a33bb6 commit d013307

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
@@ -2252,6 +2252,14 @@ def CIR_ArrayCtor : CIR_ArrayInitDestroy<"array.ctor"> {
22522252
Initialize each array element using the same C++ constructor. This
22532253
operation has one region, with one single block. The block has an
22542254
incoming argument for the current array index to initialize.
2255+
2256+
```mlir
2257+
cir.array.ctor(%0 : !cir.ptr<!cir.array<!rec_S x 42>>) {
2258+
^bb0(%arg0: !cir.ptr<!rec_S>):
2259+
cir.call @_ZN1SC1Ev(%arg0) : (!cir.ptr<!rec_S>) -> ()
2260+
cir.yield
2261+
}
2262+
```
22552263
}];
22562264
}
22572265

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ struct MissingFeatures {
255255
static bool completeDtors() { return false; }
256256
static bool vtableInitialization() { return false; }
257257
static bool msvcBuiltins() { return false; }
258+
static bool vlas() { return false; }
258259

259260
// Missing types
260261
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
@@ -815,6 +815,7 @@ CIRGenFunction::emitArrayLength(const clang::ArrayType *origArrayType,
815815
// If it's a VLA, we have to load the stored size. Note that
816816
// this is the size of the VLA in bytes, not its size in elements.
817817
if (isa<VariableArrayType>(arrayType)) {
818+
assert(cir::MissingFeatures::vlas());
818819
cgm.errorNYI(*currSrcLoc, "VLAs");
819820
return builder.getConstInt(*currSrcLoc, SizeTy, 0);
820821
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
1313
#include "clang/CIR/Dialect/IR/CIRDialect.h"
1414
#include "clang/CIR/Dialect/Passes.h"
15+
#include "clang/CIR/MissingFeatures.h"
1516

1617
#include <memory>
1718

@@ -109,6 +110,7 @@ void LoweringPreparePass::lowerArrayCtor(cir::ArrayCtor op) {
109110
builder.setInsertionPointAfter(op.getOperation());
110111

111112
mlir::Type eltTy = op->getRegion(0).getArgument(0).getType();
113+
assert(!cir::MissingFeatures::vlas());
112114
auto arrayLen =
113115
mlir::cast<cir::ArrayType>(op.getAddr().getType().getPointee()).getSize();
114116
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)