[flang-commits] [flang] [flang][OpenACC] Generalize cross-region GOTO exit handling for all ACC region ops (PR #187613)

via flang-commits flang-commits at lists.llvm.org
Mon Mar 23 02:50:42 PDT 2026


================
@@ -6239,7 +6289,22 @@ class FirConverter : public Fortran::lower::AbstractConverter {
     genConstructExitBranch(*getEval().controlSuccessor);
   }
   void genFIR(const Fortran::parser::GotoStmt &) {
-    genConstructExitBranch(*getEval().controlSuccessor);
+    auto &targetEval = *getEval().controlSuccessor;
+    mlir::Block *targetBlock = targetEval.block;
+    mlir::Region *currentRegion = &builder->getRegion();
+    if (targetBlock && targetBlock->getParent() != currentRegion &&
+        !accRegionExitStack.empty()) {
+      auto &exitInfo = accRegionExitStack.back();
+      int exitId = exitInfo.nextId++;
+      exitInfo.exits.push_back({exitId, targetBlock});
+      mlir::Value id = builder->createIntegerConstant(
+          toLocation(), builder->getI32Type(), exitId);
+      fir::StoreOp::create(*builder, toLocation(), id, exitInfo.selector);
+      Fortran::lower::genOpenACCRegionExitBranch(*builder, toLocation(),
+                                                 targetBlock);
+      return;
+    }
+    genConstructExitBranch(targetEval);
----------------
jeanPerier wrote:

I think you should move all the handling into `genBranch(mlir::Block *targetBlock)` and avoid bypassing `genConstructExitBranch` because `genConstructExitBranch` is inserting cleanups for any temporary that may have been created at the construct level. While I do not have such example, I would prefer not bypassing this clean-up step.

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


More information about the flang-commits mailing list