Skip to content

Commit 6bb7863

Browse files
authored
[CIR] Add structured CatchParamOp (#165110)
Upstream, the structured CatchParamOp as a prerequisite for implementing exception handlers Issue #154992
1 parent 9031544 commit 6bb7863

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5183,6 +5183,34 @@ def CIR_TryOp : CIR_Op<"try",[
51835183
let hasLLVMLowering = false;
51845184
}
51855185

5186+
//===----------------------------------------------------------------------===//
5187+
// CatchParamOp
5188+
//===----------------------------------------------------------------------===//
5189+
5190+
def CIR_CatchParamOp : CIR_Op<"catch_param", [HasParent<"cir::TryOp">]> {
5191+
let summary = "Represents the catch clause formal parameter";
5192+
let description = [{
5193+
The `cir.catch_param` is used to retrieves the exception object inside
5194+
the handler regions of `cir.try`.
5195+
5196+
This operation is used only before the CFG flatterning pass.
5197+
5198+
Example:
5199+
5200+
```mlir
5201+
%exception = cir.catch_param : !cir.ptr<!void>
5202+
```
5203+
}];
5204+
5205+
let results = (outs Optional<CIR_AnyType>:$param);
5206+
let assemblyFormat = [{
5207+
(`:` qualified(type($param))^)?
5208+
attr-dict
5209+
}];
5210+
5211+
let hasLLVMLowering = false;
5212+
}
5213+
51865214
//===----------------------------------------------------------------------===//
51875215
// Exception related: EhInflightOp
51885216
//===----------------------------------------------------------------------===//

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: cir-opt %s --verify-roundtrip | FileCheck %s
2+
3+
!s32i = !cir.int<s, 32>
4+
!void = !cir.void
5+
6+
module {
7+
8+
cir.func @catch_param_inside_catch() {
9+
cir.scope {
10+
cir.try {
11+
cir.yield
12+
} catch all {
13+
%exception = cir.catch_param : !cir.ptr<!void>
14+
cir.yield
15+
}
16+
}
17+
cir.return
18+
}
19+
20+
// CHECK: cir.func @catch_param_inside_catch() {
21+
// CHECK: cir.scope {
22+
// CHECK: cir.try {
23+
// CHECK: cir.yield
24+
// CHECK: } catch all {
25+
// CHECK: %[[EXCEPTION:.*]] = cir.catch_param : !cir.ptr<!void>
26+
// CHECK: cir.yield
27+
// CHECK: }
28+
// CHECK: }
29+
// CHECK: cir.return
30+
// CHECK: }
31+
32+
}

0 commit comments

Comments
 (0)