Skip to content

Commit 67c52aa

Browse files
authored
[CIR] Upstream support for IncompleteArrayType (#144138)
This change adds the basic support for IncompleteArray Issue #130197
1 parent c04fc55 commit 67c52aa

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,22 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
416416
break;
417417
}
418418

419+
case Type::IncompleteArray: {
420+
const IncompleteArrayType *arrTy = cast<IncompleteArrayType>(ty);
421+
if (arrTy->getIndexTypeCVRQualifiers() != 0)
422+
cgm.errorNYI(SourceLocation(), "non trivial array types", type);
423+
424+
mlir::Type elemTy = convertTypeForMem(arrTy->getElementType());
425+
// int X[] -> [0 x int], unless the element type is not sized. If it is
426+
// unsized (e.g. an incomplete record) just use [0 x i8].
427+
if (!builder.isSized(elemTy)) {
428+
elemTy = cgm.SInt8Ty;
429+
}
430+
431+
resultType = cir::ArrayType::get(elemTy, 0);
432+
break;
433+
}
434+
419435
case Type::ConstantArray: {
420436
const ConstantArrayType *arrTy = cast<ConstantArrayType>(ty);
421437
mlir::Type elemTy = convertTypeForMem(arrTy->getElementType());

clang/test/CIR/CodeGen/struct.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// 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">>}>>}>>}>
2020
// CIR-DAG: !rec_CycleMiddle = !cir.record<struct "CycleMiddle" {!cir.ptr<!rec_CycleEnd>}>
2121
// CIR-DAG: !rec_CycleStart = !cir.record<struct "CycleStart" {!cir.ptr<!rec_CycleMiddle>}>
22+
// CIR-DAG: !rec_IncompleteArray = !cir.record<struct "IncompleteArray" {!cir.array<!s32i x 0>}>
2223
// LLVM-DAG: %struct.CompleteS = type { i32, i8 }
2324
// LLVM-DAG: %struct.OuterS = type { %struct.InnerS, i32 }
2425
// LLVM-DAG: %struct.InnerS = type { i32, i8 }
@@ -30,6 +31,7 @@
3031
// LLVM-DAG: %struct.CycleStart = type { ptr }
3132
// LLVM-DAG: %struct.CycleMiddle = type { ptr }
3233
// LLVM-DAG: %struct.CycleEnd = type { ptr }
34+
// LLVM-DAG: %struct.IncompleteArray = type { [0 x i32] }
3335
// OGCG-DAG: %struct.CompleteS = type { i32, i8 }
3436
// OGCG-DAG: %struct.OuterS = type { %struct.InnerS, i32 }
3537
// OGCG-DAG: %struct.InnerS = type { i32, i8 }
@@ -41,6 +43,7 @@
4143
// OGCG-DAG: %struct.CycleStart = type { ptr }
4244
// OGCG-DAG: %struct.CycleMiddle = type { ptr }
4345
// OGCG-DAG: %struct.CycleEnd = type { ptr }
46+
// OGCG-DAG: %struct.IncompleteArray = type { [0 x i32] }
4447

4548
struct CompleteS {
4649
int a;
@@ -149,6 +152,16 @@ struct CycleEnd {
149152
// LLVM-DAG: @end = global %struct.CycleEnd zeroinitializer
150153
// OGCG-DAG: @end = global %struct.CycleEnd zeroinitializer
151154

155+
struct IncompleteArray {
156+
int array[];
157+
} incomplete;
158+
159+
// CIR: cir.global external @incomplete = #cir.zero : !rec_IncompleteArray
160+
161+
// LLVM-DAG: global %struct.IncompleteArray zeroinitializer
162+
163+
// OGCG-DAG: global %struct.IncompleteArray zeroinitializer
164+
152165
void f(void) {
153166
struct IncompleteS *p;
154167
}
@@ -313,3 +326,4 @@ void f6(struct CycleStart *start) {
313326
// OGCG: %[[MIDDLE:.*]] = getelementptr inbounds nuw %struct.CycleStart, ptr %{{.*}}, i32 0, i32 0
314327
// OGCG: %[[END:.*]] = getelementptr inbounds nuw %struct.CycleMiddle, ptr %{{.*}}, i32 0, i32 0
315328
// OGCG: %[[START2:.*]] = getelementptr inbounds nuw %struct.CycleEnd, ptr %{{.*}}, i32 0, i32 0
329+

0 commit comments

Comments
 (0)