[clang] [CIR] Add verifier for CIR try op (PR #181419)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 13 12:57:22 PST 2026


================
@@ -3774,6 +3774,38 @@ mlir::ValueRange cir::TryOp::getSuccessorInputs(RegionSuccessor successor) {
                               : ValueRange();
 }
 
+LogicalResult cir::TryOp::verify() {
+  mlir::ArrayAttr handlerTypes = getHandlerTypes();
+  if (!handlerTypes) {
+    if (!getHandlerRegions().empty())
+      return emitOpError(
+          "handler regions must be empty when no handler types are present");
+    return success();
+  }
+
+  mlir::MutableArrayRef<mlir::Region> handlerRegions = getHandlerRegions();
+
+  // The parser and builder won't allow this to happen, but the loop below
+  // relies on the sizes being the same, so we check it here.
+  if (handlerRegions.size() != handlerTypes.size())
+    return emitOpError(
+        "number of handler regions and handler types must match");
----------------
andykaylor wrote:

As above, you can get here by calling `addRegion` on a try op, but you can't get here via the parser.

https://github.com/llvm/llvm-project/pull/181419


More information about the cfe-commits mailing list