Skip to content

Commit 62eea86

Browse files
authored
[CIR] Update isSized with upstreamed types (#143960)
Update `isSized` function with the upstreamed types
1 parent 9a30822 commit 62eea86

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
139139
}
140140

141141
bool isSized(mlir::Type ty) {
142-
if (mlir::isa<cir::PointerType, cir::ArrayType, cir::BoolType,
143-
cir::IntType>(ty))
142+
if (mlir::isa<cir::PointerType, cir::ArrayType, cir::BoolType, cir::IntType,
143+
cir::CIRFPTypeInterface, cir::ComplexType, cir::RecordType>(
144+
ty))
144145
return true;
145146

146147
if (const auto vt = mlir::dyn_cast<cir::VectorType>(ty))

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,15 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
419419
case Type::ConstantArray: {
420420
const ConstantArrayType *arrTy = cast<ConstantArrayType>(ty);
421421
mlir::Type elemTy = convertTypeForMem(arrTy->getElementType());
422+
423+
// TODO(CIR): In LLVM, "lower arrays of undefined struct type to arrays of
424+
// i8 just to have a concrete type"
425+
if (!builder.isSized(elemTy)) {
426+
cgm.errorNYI(SourceLocation(), "arrays of undefined struct type", type);
427+
resultType = cgm.UInt32Ty;
428+
break;
429+
}
430+
422431
resultType = cir::ArrayType::get(elemTy, arrTy->getSize().getZExtValue());
423432
break;
424433
}
@@ -432,8 +441,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
432441
}
433442

434443
case Type::Enum: {
435-
const EnumDecl *ED = cast<EnumType>(ty)->getDecl();
436-
if (auto integerType = ED->getIntegerType(); !integerType.isNull())
444+
const EnumDecl *ed = cast<EnumType>(ty)->getDecl();
445+
if (auto integerType = ed->getIntegerType(); !integerType.isNull())
437446
return convertType(integerType);
438447
// Return a placeholder 'i32' type. This can be changed later when the
439448
// type is defined (see UpdateCompletedType), but is likely to be the

clang/test/CIR/CodeGen/array.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,26 @@ void func10(int *a) {
473473
// OGCG: %[[ELE:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 5
474474
// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE]], align 4
475475
// OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
476+
477+
void func11() { int _Complex a[4]; }
478+
479+
// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.complex<!s32i> x 4>, !cir.ptr<!cir.array<!cir.complex<!s32i> x 4>>, ["a"]
480+
481+
// LLVM: %[[ARR:.*]] = alloca [4 x { i32, i32 }], i64 1, align 16
482+
483+
// OGCG: %[[ARR:.*]] = alloca [4 x { i32, i32 }], align 16
484+
485+
void func12() {
486+
struct Point {
487+
int x;
488+
int y;
489+
};
490+
491+
Point a[4];
492+
}
493+
494+
// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!rec_Point x 4>, !cir.ptr<!cir.array<!rec_Point x 4>>, ["a"]
495+
496+
// LLVM: %[[ARR:.*]] = alloca [4 x %struct.Point], i64 1, align 16
497+
498+
// OGCG: %[[ARR:.*]] = alloca [4 x %struct.Point], align 16

0 commit comments

Comments
 (0)