Skip to content

Commit 720984f

Browse files
committed
Address code review comments
1 parent 3af059e commit 720984f

File tree

3 files changed

+93
-20
lines changed

3 files changed

+93
-20
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4346,11 +4346,27 @@ def CIR_TryOp : CIR_Op<"try",[
43464346
}];
43474347

43484348
// Everything already covered elsewhere.
4349-
let builders = [OpBuilder<(ins
4349+
let builders = [
4350+
OpBuilder<(ins
43504351
"llvm::function_ref<void(mlir::OpBuilder &, "
43514352
"mlir::Location)>":$tryBuilder,
43524353
"llvm::function_ref<void(mlir::OpBuilder &, mlir::Location, "
4353-
"mlir::OperationState &)>":$catchBuilder)>];
4354+
"mlir::OperationState &)>":$catchBuilder),
4355+
[{
4356+
assert(tryBuilder && "expected builder callback for 'cir.try' body");
4357+
assert(catchBuilder && "expected builder callback for 'catch' body");
4358+
4359+
OpBuilder::InsertionGuard guard($_builder);
4360+
4361+
// Try body region
4362+
Region *tryBodyRegion = $_state.addRegion();
4363+
4364+
// Create try body region and set insertion point
4365+
$_builder.createBlock(tryBodyRegion);
4366+
tryBuilder($_builder, $_state.location);
4367+
catchBuilder($_builder, $_state.location, $_state);
4368+
}]>
4369+
];
43544370

43554371
let hasLLVMLowering = false;
43564372
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,24 +2882,6 @@ LogicalResult cir::TypeInfoAttr::verify(
28822882
// TryOp
28832883
//===----------------------------------------------------------------------===//
28842884

2885-
void cir::TryOp::build(
2886-
OpBuilder &builder, OperationState &result,
2887-
function_ref<void(OpBuilder &, Location)> tryBuilder,
2888-
function_ref<void(OpBuilder &, Location, OperationState &)> catchBuilder) {
2889-
assert(tryBuilder && "expected builder callback for 'cir.try' body");
2890-
assert(catchBuilder && "expected builder callback for 'catch' body");
2891-
2892-
OpBuilder::InsertionGuard guard(builder);
2893-
2894-
// Try body region
2895-
Region *tryBodyRegion = result.addRegion();
2896-
2897-
// Create try body region and set insertion point
2898-
builder.createBlock(tryBodyRegion);
2899-
tryBuilder(builder, result.location);
2900-
catchBuilder(builder, result.location, result);
2901-
}
2902-
29032885
void cir::TryOp::getSuccessorRegions(
29042886
mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &regions) {
29052887
// If any index all the underlying regions branch back to the parent
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// RUN: cir-opt %s -verify-diagnostics -split-input-file
2+
3+
module {
4+
5+
cir.func dso_local @invalid_catch_without_all_or_type() {
6+
cir.scope {
7+
cir.try {
8+
cir.yield
9+
// expected-error @below {{'cir.try' expected attribute, 'all', or 'type' keyword}}
10+
} catch [invalid_keyword {
11+
cir.yield
12+
}]
13+
}
14+
cir.return
15+
}
16+
17+
}
18+
19+
// -----
20+
21+
module {
22+
23+
cir.func dso_local @invalid_catch_rtti_type() {
24+
cir.scope {
25+
cir.try {
26+
cir.yield
27+
// expected-error @below {{expected attribute value}}
28+
// expected-error @below {{'cir.try' expected valid RTTI info attribute}}
29+
} catch [type invalid_type {
30+
cir.yield
31+
}]
32+
}
33+
cir.return
34+
}
35+
36+
}
37+
38+
// -----
39+
40+
module {
41+
42+
cir.func dso_local @invalid_catch_empty_block() {
43+
cir.scope {
44+
cir.try {
45+
cir.yield
46+
} catch [type #cir.all {
47+
// expected-error @below {{'cir.try' catch region shall not be empty}}
48+
}]
49+
}
50+
cir.return
51+
}
52+
53+
}
54+
55+
// -----
56+
57+
!s32i = !cir.int<s, 32>
58+
59+
module {
60+
61+
cir.func dso_local @invalid_catch_not_terminated() {
62+
%a = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init]
63+
cir.scope {
64+
cir.try {
65+
cir.yield
66+
}
67+
// expected-error @below {{'cir.try' blocks are expected to be explicitly terminated}}
68+
catch [type #cir.all {
69+
%tmp_a = cir.load %a : !cir.ptr<!s32i>, !s32i
70+
}]
71+
}
72+
cir.return
73+
}
74+
75+
}

0 commit comments

Comments
 (0)