https://github.com/AmrDeveloper created https://github.com/llvm/llvm-project/pull/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 https://github.com/llvm/llvm-project/issues/154992 >From 7639d6d03d4470837174ec9a0da5cd46755829f7 Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Thu, 16 Oct 2025 22:16:28 +0200 Subject: [PATCH] [CIR] TryOp add arg default value and update diagnostic --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 4 ++-- clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 7 +++++-- clang/test/CIR/IR/invalid-try-catch.cir | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 4b26f814cbbe9..810a87a6cc768 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -4366,12 +4366,12 @@ def CIR_TryOp : CIR_Op<"try",[ let arguments = (ins UnitAttr:$synthetic, UnitAttr:$cleanup, - CIR_TryHandlerArrayAttr:$handler_types + DefaultValuedAttr<CIR_TryHandlerArrayAttr, "{}">:$handler_types ); let regions = (region AnyRegion:$try_region, - VariadicRegion<MinSizedRegion<1>>:$handler_regions + VariadicRegion<AnyRegion>:$handler_regions ); let assemblyFormat = [{ diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index 0712de2d2f182..4756c75896e0f 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -2977,8 +2977,11 @@ static mlir::ParseResult parseTryHandlerRegions( return failure(); } - if (!currRegion.empty() && !(currRegion.back().mightHaveTerminator() && - currRegion.back().getTerminator())) + if (currRegion.empty()) + return parser.emitError(regionLoc, "handler region shall not be empty"); + + if (!(currRegion.back().mightHaveTerminator() && + currRegion.back().getTerminator())) return parser.emitError( regionLoc, "blocks are expected to be explicitly terminated"); diff --git a/clang/test/CIR/IR/invalid-try-catch.cir b/clang/test/CIR/IR/invalid-try-catch.cir index 04a4d2543b8e1..94df4b63ed629 100644 --- a/clang/test/CIR/IR/invalid-try-catch.cir +++ b/clang/test/CIR/IR/invalid-try-catch.cir @@ -40,10 +40,11 @@ module { cir.func dso_local @invalid_catch_empty_block() { cir.scope { - // expected-error @below {{'cir.try' op region #1 ('handler_regions') failed to verify constraint: region with at least 1 blocks}} cir.try { cir.yield - } catch all { + } + // expected-error @below {{'cir.try' handler region shall not be empty}} + catch all { } } cir.return _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
