Skip to content

Commit e98a423

Browse files
cmarcelolanza
authored andcommitted
[CIR] Fix parsing of CIR dialect's struct type
The parsing function wasn't considering the commas separating the types inside the angle brackets, that are used by printing. Added a test to round trip a !cir.struct type to cover this code path. Related to #9.
1 parent df368fd commit e98a423

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

clang/lib/CIR/Dialect/IR/CIRTypes.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ Type StructType::parse(mlir::AsmParser &parser) {
7676
if (parser.parseString(&typeName))
7777
return Type();
7878
llvm::SmallVector<Type> members;
79-
Type nextMember;
80-
while (mlir::succeeded(parser.parseType(nextMember)))
79+
while (mlir::succeeded(parser.parseOptionalComma())) {
80+
Type nextMember;
81+
if (parser.parseType(nextMember))
82+
return Type();
8183
members.push_back(nextMember);
84+
}
8285
if (parser.parseGreater())
8386
return Type();
8487
return get(parser.getContext(), members, typeName);

clang/test/CIR/IR/struct.cir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: cir-tool %s | cir-tool | FileCheck %s
2+
3+
module {
4+
cir.func @structs() {
5+
%0 = cir.alloca !cir.ptr<!cir.struct<"S", i8, i16, i32>>, cir.ptr <!cir.ptr<!cir.struct<"S", i8, i16, i32>>>, ["s", init]
6+
cir.return
7+
}
8+
}
9+
10+
// CHECK: cir.func @structs() {
11+
// CHECK-NEXT: %0 = cir.alloca !cir.ptr<!cir.struct<"S", i8, i16, i32>>, cir.ptr <!cir.ptr<!cir.struct<"S", i8, i16, i32>>>, ["s", init]

0 commit comments

Comments
 (0)