[llvm-branch-commits] [flang] [flang] Do not branch to a FORMAT statement from an assigned GO TO (PR #217220)

Kareem Ergawy via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Aug 21 02:06:46 PDT 2026


================
@@ -1233,7 +1233,27 @@ bool CheckConstraints(ParseTreeAnalyzer &&parseTreeAnalysis) {
   return !context.AnyFatalError();
 }
 
-bool ValidateLabels(SemanticsContext &context, const parser::Program &program) {
-  return CheckConstraints(LabelAnalysis(context, program));
+// Record the statements that a branch may name, for lowering to consult when
+// it records the targets of a branch.  Statements are identified by source
+// position because a label is only unique within one program unit.
+static void RecordBranchTargets(
+    const ParseTreeAnalyzer &analysis, SemanticsContext &context) {
+  for (const auto &programUnit : analysis.ProgramUnits()) {
+    for (const auto &[label, info] : programUnit.targetStmts) {
+      if (info.labeledStmtClassificationSet.test(TargetStatementEnum::Branch)) {
+        context.RecordBranchTarget(info.parserCharBlock);
+      }
+    }
+  }
+}
+
+bool AnalyzeLabels(SemanticsContext &context, const parser::Program &program) {
+  ParseTreeAnalyzer analysis{LabelAnalysis(context, program)};
+  if (!CheckConstraints(analysis, context)) {
+    // The program will not be lowered, so there is nothing to record for.
----------------
ergawy wrote:

Done in 6d3274b48ed580f1a759895bfea11694af4cb719.

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


More information about the llvm-branch-commits mailing list