[clang] [CIR] Implement flattening for cleanup scopes with multiple exits (PR #180627)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 10 06:39:34 PST 2026


================
@@ -725,21 +725,105 @@ class CIRTernaryOpFlattening : public mlir::OpRewritePattern<cir::TernaryOp> {
   }
 };
 
+// Get or create the cleanup destination slot for a function. This slot is
+// shared across all cleanup scopes in the function to track which exit path
+// to take after running cleanup code when there are multiple exits.
+static cir::AllocaOp getOrCreateCleanupDestSlot(cir::FuncOp funcOp,
+                                                mlir::PatternRewriter &rewriter,
+                                                mlir::Location loc) {
+  mlir::Block &entryBlock = funcOp.getBody().front();
+
+  // Look for an existing cleanup dest slot in the entry block.
+  for (auto &op : entryBlock) {
+    if (auto existingAlloca = dyn_cast<cir::AllocaOp>(&op)) {
+      if (existingAlloca.getName() == "__cleanup_dest_slot")
----------------
erichkeane wrote:

Could this all be a llvm::find_if kinda thing? 

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


More information about the cfe-commits mailing list