[flang-commits] [flang] [flang][PFT] record every target of an assigned GO TO (PR #210065)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Thu Jul 16 10:11:53 PDT 2026


================
@@ -1039,10 +1039,29 @@ class PFTBuilder {
               iter->second.insert(label);
             }
           },
-          [&](const parser::AssignedGotoStmt &) {
-            // Although this statement is a branch, it doesn't have any
-            // explicit control successors. So the code at the end of the
-            // loop won't mark the successor. Do that here.
+          [&](const parser::AssignedGotoStmt &s) {
+            // Mark every possible target of the assigned GO TO so that
+            // wrappability analyses (branchesAreInternal, hasIncomingBranch)
+            // can see any escape from an enclosing construct.
+            const auto &labelList = std::get<std::list<parser::Label>>(s.t);
+            if (!labelList.empty()) {
+              // Explicit target list: `go to v, (l1, l2, ...)`.
+              for (const auto &label : labelList)
+                markBranchTarget(eval, label);
+            } else {
+              // No explicit list (`go to v`): fall back to the set of labels
+              // that have been previously ASSIGN'd to v.
+              // TODO: This may miss assignments that appear later in program
+              // order, but it matches the information available at this point
+              // in the walk.
----------------
ergawy wrote:

> I wonder if we should avoid generating scf.execute_region in this case?

I think yes. I think, we should bail out in that case.

> Would that break how you intend to build on top of your other PR?

Most likely, because a branch from within the execute_region would point to a block outside.

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


More information about the flang-commits mailing list