https://github.com/AmrDeveloper created https://github.com/llvm/llvm-project/pull/173306
Add LandingpadOp for the new design of Exceptions Issue https://github.com/llvm/llvm-project/issues/154992 >From f73ea42d6cc168a973bcc699ee4329166f33800d Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Mon, 22 Dec 2025 21:31:33 +0100 Subject: [PATCH] [CIR] Exception handling LandingpadOp --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 27 +++++++++++++++++++ .../include/clang/CIR/Dialect/IR/CIRTypes.td | 8 ++++++ clang/test/CIR/IR/eh-landingpad.cir | 15 +++++++++++ 3 files changed, 50 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 86ea5fca75200..370485e2fc97a 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -5516,6 +5516,33 @@ def CIR_EhInflightOp : CIR_Op<"eh.inflight_exception"> { }]; } +//===----------------------------------------------------------------------===// +// 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 fe79e3a086d4e..f6a0348e9dfc8 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td @@ -735,4 +735,12 @@ def CIR_AnyType : AnyTypeOf<[ CIR_ComplexType, CIR_VPtrType, CIR_DataMemberType ]>; +//===----------------------------------------------------------------------===// +// 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: } + +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
