[clang] 92757f9 - [CIR] TryOp add arg default value and update diagnostic (#163856)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 17 09:46:55 PDT 2025


Author: Amr Hesham
Date: 2025-10-17T18:46:51+02:00
New Revision: 92757f9de34a5f08873064be0e30d7cdeaae895f

URL: https://github.com/llvm/llvm-project/commit/92757f9de34a5f08873064be0e30d7cdeaae895f
DIFF: https://github.com/llvm/llvm-project/commit/92757f9de34a5f08873064be0e30d7cdeaae895f.diff

LOG: [CIR] TryOp add arg default value and update diagnostic (#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

Added: 
    

Modified: 
    clang/include/clang/CIR/Dialect/IR/CIROps.td
    clang/lib/CIR/Dialect/IR/CIRDialect.cpp
    clang/test/CIR/IR/invalid-try-catch.cir

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 91db36c250aac..e0163a4fecd5f 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -4408,12 +4408,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 f03b891079f63..b4c37048cbe5b 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -3011,8 +3011,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


        


More information about the cfe-commits mailing list