[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:39 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) {
----------------
erichkeane wrote:

```suggestion
  for (Operation &op : entryBlock) {
```
?? 

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


More information about the cfe-commits mailing list