[flang-commits] [flang] cabe29e - [flang][OpenMP] Clear branch labels in all program units (#194152)
via flang-commits
flang-commits at lists.llvm.org
Sat Apr 25 08:41:14 PDT 2026
Author: Krzysztof Parzyszek
Date: 2026-04-25T10:41:09-05:00
New Revision: cabe29eb6e0760bee7be4b31968a0e1bbb32f51a
URL: https://github.com/llvm/llvm-project/commit/cabe29eb6e0760bee7be4b31968a0e1bbb32f51a
DIFF: https://github.com/llvm/llvm-project/commit/cabe29eb6e0760bee7be4b31968a0e1bbb32f51a.diff
LOG: [flang][OpenMP] Clear branch labels in all program units (#194152)
The semantic check for branching in or out of an OpenMP construct did
not reset its label information in some cases, leading to false positive
error messages in valid Fortran code.
Added:
flang/test/Semantics/OpenMP/branching-program-unit.f90
Modified:
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 30db2f2ad4ec5..b46bae6ee70d4 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -69,6 +69,10 @@ OmpStructureChecker::OmpStructureChecker(SemanticsContext &context)
scopeStack_.push_back(&context.globalScope());
}
+void OmpStructureChecker::Enter(const parser::ProgramUnit &) { //
+ ClearLabels();
+}
+
bool OmpStructureChecker::Enter(const parser::MainProgram &x) {
using StatementProgramStmt = parser::Statement<parser::ProgramStmt>;
if (auto &stmt{std::get<std::optional<StatementProgramStmt>>(x.t)}) {
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index ce0061594b9fd..35ffe7d1582ca 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -71,6 +71,7 @@ class OmpStructureChecker : public OmpStructureCheckerBase {
using llvmOmpClause = const llvm::omp::Clause;
+ void Enter(const parser::ProgramUnit &);
bool Enter(const parser::MainProgram &);
void Leave(const parser::MainProgram &);
bool Enter(const parser::BlockData &);
diff --git a/flang/test/Semantics/OpenMP/branching-program-unit.f90 b/flang/test/Semantics/OpenMP/branching-program-unit.f90
new file mode 100644
index 0000000000000..6f6ec3e6cb5fe
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/branching-program-unit.f90
@@ -0,0 +1,16 @@
+!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
+
+! This should pass semantic checks.
+
+!CHECK: func.func
+
+subroutine f
+ 10 continue
+end
+
+subroutine g
+ !$omp parallel
+ goto 10
+ 10 continue
+ !$omp end parallel
+end
More information about the flang-commits
mailing list