[clang] [CIR] Fix multiple returns in switch statements (PR #164468)

Morris Hafner via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 31 04:01:40 PDT 2025


================
@@ -242,12 +242,15 @@ void CIRGenFunction::LexicalScope::cleanup() {
     }
   };
 
-  if (returnBlock != nullptr) {
-    // Write out the return block, which loads the value from `__retval` and
-    // issues the `cir.return`.
+  // Cleanup are done right before codegen resumes a scope. This is where
+  // objects are destroyed. Process all return blocks.
----------------
mmha wrote:

Thanks for pointing this out. I'll update the comment to reflect this. The code you linked wouldn't work here as this would mean branching out of the case region, so all the cleanup code would have to be emitted for every early exit. Not great. Maybe we should leave this as a TODO until we get early exits in MLIR unless this blocks us from anything important.

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


More information about the cfe-commits mailing list