Skip to content

Commit 05e1171

Browse files
committed
Address code review comments
1 parent 7837cc3 commit 05e1171

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
@@ -4375,11 +4375,27 @@ def CIR_TryOp : CIR_Op<"try",[
43754375
}];
43764376

43774377
// Everything already covered elsewhere.
4378-
let builders = [OpBuilder<(ins
4378+
let builders = [
4379+
OpBuilder<(ins
43794380
"llvm::function_ref<void(mlir::OpBuilder &, "
43804381
"mlir::Location)>":$tryBuilder,
43814382
"llvm::function_ref<void(mlir::OpBuilder &, mlir::Location, "
4382-
"mlir::OperationState &)>":$catchBuilder)>];
4383+
"mlir::OperationState &)>":$catchBuilder),
4384+
[{
4385+
assert(tryBuilder && "expected builder callback for 'cir.try' body");
4386+
assert(catchBuilder && "expected builder callback for 'catch' body");
4387+
4388+
OpBuilder::InsertionGuard guard($_builder);
4389+
4390+
// Try body region
4391+
Region *tryBodyRegion = $_state.addRegion();
4392+
4393+
// Create try body region and set insertion point
4394+
$_builder.createBlock(tryBodyRegion);
4395+
tryBuilder($_builder, $_state.location);
4396+
catchBuilder($_builder, $_state.location, $_state);
4397+
}]>
4398+
];
43834399

43844400
let hasLLVMLowering = false;
43854401
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,24 +2918,6 @@ LogicalResult cir::TypeInfoAttr::verify(
29182918
// TryOp
29192919
//===----------------------------------------------------------------------===//
29202920

2921-
void cir::TryOp::build(
2922-
OpBuilder &builder, OperationState &result,
2923-
function_ref<void(OpBuilder &, Location)> tryBuilder,
2924-
function_ref<void(OpBuilder &, Location, OperationState &)> catchBuilder) {
2925-
assert(tryBuilder && "expected builder callback for 'cir.try' body");
2926-
assert(catchBuilder && "expected builder callback for 'catch' body");
2927-
2928-
OpBuilder::InsertionGuard guard(builder);
2929-
2930-
// Try body region
2931-
Region *tryBodyRegion = result.addRegion();
2932-
2933-
// Create try body region and set insertion point
2934-
builder.createBlock(tryBodyRegion);
2935-
tryBuilder(builder, result.location);
2936-
catchBuilder(builder, result.location, result);
2937-
}
2938-
29392921
void cir::TryOp::getSuccessorRegions(
29402922
mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &regions) {
29412923
// 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)