[clang] [CIR] Add flattened version of CatchParamOp (PR #172713)

Henrich Lauko via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 20 00:22:06 PST 2025


================
@@ -3418,6 +3418,30 @@ mlir::LogicalResult CIRToLLVMEhInflightOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMCatchParamFlatOpLowering::matchAndRewrite(
+    cir::CatchParamFlatOp op, OpAdaptor adaptor,
+    mlir::ConversionPatternRewriter &rewriter) const {
+  if (op.getKind() == cir::FlatCatchParamKind::Begin) {
+    StringRef fnName = "__cxa_begin_catch";
+    auto llvmPtrTy = mlir::LLVM::LLVMPointerType::get(rewriter.getContext());
+    auto fnTy = mlir::LLVM::LLVMFunctionType::get(llvmPtrTy, {llvmPtrTy});
+    createLLVMFuncOpIfNotExist(rewriter, op, fnName, fnTy);
+    rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(
+        op, mlir::TypeRange{llvmPtrTy}, fnName,
+        mlir::ValueRange{adaptor.getExceptionPtr()});
+    return mlir::success();
+  }
+
+  assert(op.getKind() == cir::FlatCatchParamKind::End);
+  StringRef fnName = "__cxa_end_catch";
+  auto fnTy = mlir::LLVM::LLVMFunctionType::get(
+      mlir::LLVM::LLVMVoidType::get(rewriter.getContext()), {});
+  createLLVMFuncOpIfNotExist(rewriter, op, fnName, fnTy);
+  rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(op, mlir::TypeRange{}, fnName,
+                                                  mlir::ValueRange{});
+  return mlir::success();
----------------
xlauko wrote:

Do we already have nounwind upsreamed? This should either set that attribute or add NYI assert here.

https://github.com/llvm/llvm-project/pull/172713


More information about the cfe-commits mailing list