Skip to content

Commit 92757f9

Browse files
authored
[CIR] TryOp add arg default value and update diagnostic (llvm#163856)
- Add a default value to handler_types to be able to construct TryOp, then modify the handlers. - Move empty region diagnostic from tablegen constraints to C++, because we need the ability to add an empty region, then modify it later, for example, in the handlers builder, but we need to report an error when we find it in the IR while parsing. Issue llvm#154992
1 parent df2ff3a commit 92757f9

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,12 +4408,12 @@ def CIR_TryOp : CIR_Op<"try",[
44084408
let arguments = (ins
44094409
UnitAttr:$synthetic,
44104410
UnitAttr:$cleanup,
4411-
CIR_TryHandlerArrayAttr:$handler_types
4411+
DefaultValuedAttr<CIR_TryHandlerArrayAttr, "{}">:$handler_types
44124412
);
44134413

44144414
let regions = (region
44154415
AnyRegion:$try_region,
4416-
VariadicRegion<MinSizedRegion<1>>:$handler_regions
4416+
VariadicRegion<AnyRegion>:$handler_regions
44174417
);
44184418

44194419
let assemblyFormat = [{

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3011,8 +3011,11 @@ static mlir::ParseResult parseTryHandlerRegions(
30113011
return failure();
30123012
}
30133013

3014-
if (!currRegion.empty() && !(currRegion.back().mightHaveTerminator() &&
3015-
currRegion.back().getTerminator()))
3014+
if (currRegion.empty())
3015+
return parser.emitError(regionLoc, "handler region shall not be empty");
3016+
3017+
if (!(currRegion.back().mightHaveTerminator() &&
3018+
currRegion.back().getTerminator()))
30163019
return parser.emitError(
30173020
regionLoc, "blocks are expected to be explicitly terminated");
30183021

clang/test/CIR/IR/invalid-try-catch.cir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ module {
4040

4141
cir.func dso_local @invalid_catch_empty_block() {
4242
cir.scope {
43-
// expected-error @below {{'cir.try' op region #1 ('handler_regions') failed to verify constraint: region with at least 1 blocks}}
4443
cir.try {
4544
cir.yield
46-
} catch all {
45+
}
46+
// expected-error @below {{'cir.try' handler region shall not be empty}}
47+
catch all {
4748
}
4849
}
4950
cir.return

0 commit comments

Comments
 (0)