Skip to content

Commit 75a15a2

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 cb45aba commit 75a15a2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

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

clang/test/CIR/IR/struct.cir

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