Author: Amr Hesham
Date: 2025-12-06T14:56:51+01:00
New Revision: 6bb786398efdbc496edd517e682caeaaefd46f6e

URL: 
https://github.com/llvm/llvm-project/commit/6bb786398efdbc496edd517e682caeaaefd46f6e
DIFF: 
https://github.com/llvm/llvm-project/commit/6bb786398efdbc496edd517e682caeaaefd46f6e.diff

LOG: [CIR] Add structured CatchParamOp (#165110)

Upstream, the structured CatchParamOp as a prerequisite for implementing
exception handlers

Issue https://github.com/llvm/llvm-project/issues/154992

Added: 
    clang/test/CIR/IR/catch-param.cir

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

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index caa047a51b689..fcc7585cf81a5 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -5183,6 +5183,34 @@ def CIR_TryOp : CIR_Op<"try",[
   let hasLLVMLowering = false;
 }
 
+//===----------------------------------------------------------------------===//
+// CatchParamOp
+//===----------------------------------------------------------------------===//
+
+def CIR_CatchParamOp : CIR_Op<"catch_param", [HasParent<"cir::TryOp">]> {
+  let summary = "Represents the catch clause formal parameter";
+  let description = [{
+    The `cir.catch_param` is used to retrieves the exception object inside
+    the handler regions of `cir.try`.
+
+    This operation is used only before the CFG flatterning pass.
+
+    Example:
+
+    ```mlir
+    %exception = cir.catch_param : !cir.ptr<!void>
+    ```
+  }];
+
+  let results = (outs Optional<CIR_AnyType>:$param);
+  let assemblyFormat = [{
+    (`:` qualified(type($param))^)?
+    attr-dict
+  }];
+
+  let hasLLVMLowering = false;
+}
+
 
//===----------------------------------------------------------------------===//
 // Exception related: EhInflightOp
 
//===----------------------------------------------------------------------===//

diff  --git a/clang/test/CIR/IR/catch-param.cir 
b/clang/test/CIR/IR/catch-param.cir
new file mode 100644
index 0000000000000..7b0f884fff11d
--- /dev/null
+++ b/clang/test/CIR/IR/catch-param.cir
@@ -0,0 +1,32 @@
+// RUN: cir-opt %s --verify-roundtrip | FileCheck %s  
+
+!s32i = !cir.int<s, 32>
+!void = !cir.void
+
+module {
+
+cir.func @catch_param_inside_catch() {
+  cir.scope {
+    cir.try {
+      cir.yield
+    } catch all {
+      %exception = cir.catch_param : !cir.ptr<!void>
+      cir.yield
+    }
+  }
+  cir.return
+}
+
+// CHECK: cir.func @catch_param_inside_catch() {
+// CHECK:   cir.scope {
+// CHECK:     cir.try {
+// CHECK:       cir.yield
+// CHECK:     } catch all {
+// CHECK:       %[[EXCEPTION:.*]] = cir.catch_param : !cir.ptr<!void> 
+// CHECK:       cir.yield
+// CHECK:     }
+// CHECK:   }
+// CHECK:   cir.return
+// CHECK: }
+
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to