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 + ``` + }]; + + let results = (outs Optional:$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 +!void = !cir.void + +module { + +cir.func @catch_param_inside_catch() { + cir.scope { + cir.try { + cir.yield + } catch all { + %exception = cir.catch_param : !cir.ptr + 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 +// CHECK: cir.yield +// CHECK: } +// CHECK: } +// CHECK: cir.return +// CHECK: } + +}