[flang-commits] [flang] [flang][OpenMP] Clear branch labels in all program units (PR #194152)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Sat Apr 25 08:22:19 PDT 2026


https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/194152

>From 9f318728db2d22470e74fe700503969559759367 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Sat, 25 Apr 2026 10:18:02 -0500
Subject: [PATCH 1/2] [flang][OpenMP] Clear branch labels in all program units

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.
---
 flang/lib/Semantics/check-omp-structure.cpp      |  4 ++++
 flang/lib/Semantics/check-omp-structure.h        |  1 +
 .../Semantics/OpenMP/branching-program-unit.f90  | 16 ++++++++++++++++
 3 files changed, 21 insertions(+)
 create mode 100644 flang/test/Semantics/OpenMP/branching-program-unit.f90

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 30db2f2ad4ec5..13d5f9294e5a5 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

>From b8e2e2a8f41b6fed8932dbd94dc6a6d26dbb43f0 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Sat, 25 Apr 2026 10:22:07 -0500
Subject: [PATCH 2/2] format

---
 flang/lib/Semantics/check-omp-structure.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 13d5f9294e5a5..b46bae6ee70d4 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -69,7 +69,7 @@ OmpStructureChecker::OmpStructureChecker(SemanticsContext &context)
   scopeStack_.push_back(&context.globalScope());
 }
 
-void OmpStructureChecker::Enter(const parser::ProgramUnit &) {
+void OmpStructureChecker::Enter(const parser::ProgramUnit &) { //
   ClearLabels();
 }
 



More information about the flang-commits mailing list