[clang] [CIR] Exception handling LandingpadOp (PR #173306)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 11 10:55:51 PST 2026
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/173306
>From cd8bbb99dc6527b6bde78545b03e98ab38bfaa34 Mon Sep 17 00:00:00 2001
From: Amr Hesham <amr96 at programmer.net>
Date: Mon, 22 Dec 2025 21:31:33 +0100
Subject: [PATCH] [CIR] Exception handling LandingpadOp
---
clang/include/clang/CIR/Dialect/IR/CIROps.td | 26 +++++++++++++++++++
.../include/clang/CIR/Dialect/IR/CIRTypes.td | 8 ++++++
clang/test/CIR/IR/eh-landingpad.cir | 15 +++++++++++
3 files changed, 49 insertions(+)
create mode 100644 clang/test/CIR/IR/eh-landingpad.cir
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index cf7e398e53cd4..5e3bb07147ffe 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -5658,6 +5658,32 @@ def CIR_EhTypeIdOp : CIR_Op<"eh.typeid",
}];
}
+// Exception related: EhLandingpadOp
+//===----------------------------------------------------------------------===//
+def CIR_EhLandingpadOp : CIR_Op<"eh.landingpad"> {
+ let summary = "Materialize the catch clause formal parameter";
+ let description = [{
+ This operation is expected to be the first operation in the unwind
+ destination basic blocks of a `cir.try_call` operation.
+
+ `cir.eh.landingpad` returns eh_token which lowered to exception_ptr and
+ type_id except for Windows platform it will be lowered to none to represent
+ funclet token.
+
+ Example:
+ ```mlir
+ %eh_token = cir.eh_landingpad
+ ```
+ }];
+
+ let results = (outs CIR_EhToken:$eh_token);
+ let assemblyFormat = [{
+ attr-dict
+ }];
+
+ let hasLLVMLowering = false;
+}
+
//===----------------------------------------------------------------------===//
// Atomic operations
//===----------------------------------------------------------------------===//
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index 5ba7726e9b1a6..ac8f8d7579b8d 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -763,4 +763,12 @@ def CIR_AnyType : AnyTypeOf<[
CIR_ComplexType, CIR_VPtrType, CIR_DataMemberType, CIR_MethodType
]>;
+//===----------------------------------------------------------------------===//
+// Exception related: EhToken type
+//===----------------------------------------------------------------------===//
+
+def CIR_EhToken : CIR_Type<"EhToken", "eh_token"> {
+ let summary = "CIR Exception handling token";
+}
+
#endif // CLANG_CIR_DIALECT_IR_CIRTYPES_TD
diff --git a/clang/test/CIR/IR/eh-landingpad.cir b/clang/test/CIR/IR/eh-landingpad.cir
new file mode 100644
index 0000000000000..47325b3005820
--- /dev/null
+++ b/clang/test/CIR/IR/eh-landingpad.cir
@@ -0,0 +1,15 @@
+// RUN: cir-opt %s --verify-roundtrip | FileCheck %s
+
+module {
+
+cir.func dso_local @exception_landingpad() {
+ %eh_token = cir.eh.landingpad
+ cir.return
+}
+
+// CHECK: cir.func dso_local @exception_landingpad() {
+// CHECK: %[[EH_TOKEN:.*]] = cir.eh.landingpad
+// CHECK: cir.return
+// CHECK: }
+
+}
More information about the cfe-commits
mailing list