[clang] [CIR] Upstream CIR Dialect TryOp with Catch Attrs (PR #162897)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 10 14:48:19 PDT 2025
================
@@ -4296,6 +4296,81 @@ def CIR_AllocExceptionOp : CIR_Op<"alloc.exception"> {
}];
}
+//===----------------------------------------------------------------------===//
+// TryOp
+//===----------------------------------------------------------------------===//
+
+def CIR_TryOp : CIR_Op<"try",[
+ DeclareOpInterfaceMethods<RegionBranchOpInterface>,
+ RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments
+]> {
+ let summary = "C++ try block";
+ let description = [{
+ Holds the lexical scope of `try {}`. Note that resources used on catch
+ clauses are usually allocated in the same parent as `cir.try`.
+
+ `synthetic`: use `cir.try` to represent try/catches not originally
+ present in the source code (e.g. `g = new Class` under `-fexceptions`).
----------------
andykaylor wrote:
```suggestion
present in the source code. For example, a synthetic `cir.try` region
is created around the constructor call when `operator new` is used
so that the memory allocated will be freed if the constructor throws
an exception.
```
https://github.com/llvm/llvm-project/pull/162897
More information about the cfe-commits
mailing list