[clang] [CIR] Introduce cir.construct_catch_param (PR #195283)

Henrich Lauko via cfe-commits cfe-commits at lists.llvm.org
Mon May 4 10:46:51 PDT 2026


================
@@ -7704,6 +7704,57 @@ def CIR_InitCatchParamOp : CIR_Op<"init_catch_param"> {
   let hasLLVMLowering = false;
 }
 
+//===----------------------------------------------------------------------===//
+// EH Operations: ConstructCatchParamOp
+//===----------------------------------------------------------------------===//
+
+def CIR_ConstructCatchParamOp : CIR_Op<"construct_catch_param", [
+    DeclareOpInterfaceMethods<SymbolUserOpInterface>
+  ]> {
+  let summary = "Construct a catch parameter from the in-flight exception";
+  let description = [{
+    `cir.construct_catch_param` abstractly represents the target-specific work
+    that must be performed before `cir.begin_catch` to bind the in-flight
+    exception object to the local alloca used for the catch parameter.
+
+    For example, for non-pointer, non-reference catch parameters whose type has
+    a non-trivial copy constructor, the Itanium C++ ABI requires
+    calling `__cxa_get_exception_ptr` to obtain the adjusted exception pointer
+    and then invoking the catch parameter's copy constructor to create a local
+    copy of the object before `__cxa_begin_catch` is invoked.
+
+    This operation takes a `!cir.eh_token` that represents the in-flight
+    exception and the alloca value that is used for the local copy of the
+    exception object. The `copy_fn` attribute is a flat symbol reference to a
+    `cir.func` thunk that copies the exception object to a local alloca value.
+
+    This operation is replaced with a target-specific representation during
+    the EHABI lowering pass. For some targets, such as the Microsoft ABI,
+    this operation is a no-op and is simply erased during lowering.
+
+    Example:
+
+    ```
+    cir.construct_catch_param non_trivial_copy %eh_token to %param_addr
+      copy_fn = @__clang_cir_catch_init_T : !cir.eh_token, !cir.ptr<!rec_T>
+    ```
+  }];
+
+  let arguments = (ins
+      CIR_EhTokenType:$eh_token,
+      CIR_PointerType:$param_addr,
+      CIR_InitCatchKind:$kind,
+      FlatSymbolRefAttr:$copy_fn
+  );
+
+  let assemblyFormat = [{
+    $kind $eh_token `to` $param_addr `:` qualified(type($eh_token)) `,`
+      qualified(type($param_addr)) `,` `copy_fn` `=` $copy_fn attr-dict
----------------
xlauko wrote:

copy_is attribute, so it does not have a type, also `eh_token` can be implicit, since there can be only one buildable type, so I guess: 
```
    $kind $eh_token `to` $param_addr `using` $copy_fn `:` qualified(type($param_addr)) attr-dict
```
should work :) 

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


More information about the cfe-commits mailing list