Skip to content

Commit f6aaa4d

Browse files
committed
update test & improve parsing
1 parent 15a4a12 commit f6aaa4d

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,18 +2454,25 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
24542454
return failure();
24552455

24562456
mlir::Type type;
2457-
bool defaultCtor = false, copyCtor = false;
24582457
if (parser.parseType(type).failed())
24592458
return failure();
2459+
2460+
bool defaultCtor = false, copyCtor = false;
24602461
if (mlir::succeeded(parser.parseOptionalComma())) {
2461-
if (mlir::succeeded(parser.parseOptionalKeyword("default")))
2462-
defaultCtor = true;
2463-
if (mlir::succeeded(parser.parseOptionalKeyword("copy")))
2464-
copyCtor = true;
2462+
if (parser
2463+
.parseCommaSeparatedList([&]() {
2464+
if (mlir::succeeded(parser.parseOptionalKeyword("default")))
2465+
defaultCtor = true;
2466+
else if (mlir::succeeded(parser.parseOptionalKeyword("copy")))
2467+
copyCtor = true;
2468+
else
2469+
return failure();
2470+
return success();
2471+
})
2472+
.failed())
2473+
return failure();
24652474
}
2466-
if (mlir::succeeded(parser.parseOptionalComma()))
2467-
if (mlir::succeeded(parser.parseOptionalKeyword("copy")))
2468-
copyCtor = true;
2475+
24692476
if (parser.parseGreater().failed())
24702477
return failure();
24712478

clang/test/CIR/IR/cxx-special-member.cir

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: cir-opt %s
1+
// RUN: cir-opt %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
23

34
!s32i = !cir.int<s, 32>
45
!rec_S = !cir.record<struct "S" {!s32i}>
@@ -8,3 +9,12 @@ module {
89
cir.func private @_ZN1SC2Ev(!cir.ptr<!rec_S>) ctor<!rec_S, default>
910
cir.func private @_ZN1SD2Ev(!cir.ptr<!rec_S>) dtor<!rec_S>
1011
}
12+
13+
// CHECK: !s32i = !cir.int<s, 32>
14+
// CHECK: !rec_S = !cir.record<struct "S" {!s32i}>
15+
// CHECK: module {
16+
// CHECK: cir.func private @_ZN1SC1ERKS_(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) ctor<!rec_S, copy>
17+
// CHECK: cir.func private @_ZN1SC2Ei(!cir.ptr<!rec_S>, !cir.ptr<!rec_S>) ctor<!rec_S>
18+
// CHECK: cir.func private @_ZN1SC2Ev(!cir.ptr<!rec_S>) ctor<!rec_S, default>
19+
// CHECK: cir.func private @_ZN1SD2Ev(!cir.ptr<!rec_S>) dtor<!rec_S>
20+
// CHECK: }

0 commit comments

Comments
 (0)