Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,22 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
break;
}

case Type::IncompleteArray: {
const IncompleteArrayType *arrTy = cast<IncompleteArrayType>(ty);
if (arrTy->getIndexTypeCVRQualifiers() != 0)
cgm.errorNYI(SourceLocation(), "non trivial array types", type);

mlir::Type elemTy = convertTypeForMem(arrTy->getElementType());
// int X[] -> [0 x int], unless the element type is not sized. If it is
// unsized (e.g. an incomplete record) just use [0 x i8].
if (!builder.isSized(elemTy)) {
elemTy = cgm.SInt8Ty;
}

resultType = cir::ArrayType::get(elemTy, 0);
break;
}

case Type::ConstantArray: {
const ConstantArrayType *arrTy = cast<ConstantArrayType>(ty);
mlir::Type elemTy = convertTypeForMem(arrTy->getElementType());
Expand Down
14 changes: 14 additions & 0 deletions clang/test/CIR/CodeGen/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// CIR-DAG: !rec_CycleEnd = !cir.record<struct "CycleEnd" {!cir.ptr<!cir.record<struct "CycleStart" {!cir.ptr<!cir.record<struct "CycleMiddle" {!cir.ptr<!cir.record<struct "CycleEnd">>}>>}>>}>
// CIR-DAG: !rec_CycleMiddle = !cir.record<struct "CycleMiddle" {!cir.ptr<!rec_CycleEnd>}>
// CIR-DAG: !rec_CycleStart = !cir.record<struct "CycleStart" {!cir.ptr<!rec_CycleMiddle>}>
// CIR-DAG: !rec_IncompleteArray = !cir.record<struct "IncompleteArray" {!cir.array<!s32i x 0>}>
// LLVM-DAG: %struct.CompleteS = type { i32, i8 }
// LLVM-DAG: %struct.OuterS = type { %struct.InnerS, i32 }
// LLVM-DAG: %struct.InnerS = type { i32, i8 }
Expand All @@ -30,6 +31,7 @@
// LLVM-DAG: %struct.CycleStart = type { ptr }
// LLVM-DAG: %struct.CycleMiddle = type { ptr }
// LLVM-DAG: %struct.CycleEnd = type { ptr }
// LLVM-DAG: %struct.IncompleteArray = type { [0 x i32] }
// OGCG-DAG: %struct.CompleteS = type { i32, i8 }
// OGCG-DAG: %struct.OuterS = type { %struct.InnerS, i32 }
// OGCG-DAG: %struct.InnerS = type { i32, i8 }
Expand All @@ -41,6 +43,7 @@
// OGCG-DAG: %struct.CycleStart = type { ptr }
// OGCG-DAG: %struct.CycleMiddle = type { ptr }
// OGCG-DAG: %struct.CycleEnd = type { ptr }
// OGCG-DAG: %struct.IncompleteArray = type { [0 x i32] }

struct CompleteS {
int a;
Expand Down Expand Up @@ -149,6 +152,16 @@ struct CycleEnd {
// LLVM-DAG: @end = global %struct.CycleEnd zeroinitializer
// OGCG-DAG: @end = global %struct.CycleEnd zeroinitializer

struct IncompleteArray {
int array[];
} incomplete;

// CIR: cir.global external @incomplete = #cir.zero : !rec_IncompleteArray

// LLVM-DAG: global %struct.IncompleteArray zeroinitializer

// OGCG-DAG: global %struct.IncompleteArray zeroinitializer

void f(void) {
struct IncompleteS *p;
}
Expand Down Expand Up @@ -313,3 +326,4 @@ void f6(struct CycleStart *start) {
// OGCG: %[[MIDDLE:.*]] = getelementptr inbounds nuw %struct.CycleStart, ptr %{{.*}}, i32 0, i32 0
// OGCG: %[[END:.*]] = getelementptr inbounds nuw %struct.CycleMiddle, ptr %{{.*}}, i32 0, i32 0
// OGCG: %[[START2:.*]] = getelementptr inbounds nuw %struct.CycleEnd, ptr %{{.*}}, i32 0, i32 0

Loading