[flang-commits] [flang] [Flang][OpenMP] Allow workdistribute inside 'target teams' (PR #199006)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Thu May 21 05:35:21 PDT 2026


https://github.com/skatrak updated https://github.com/llvm/llvm-project/pull/199006

>From a107d37f692893de1487b9d9fa92532df627ed3a Mon Sep 17 00:00:00 2001
From: Sergio Afonso <Sergio.AfonsoFumero at amd.com>
Date: Thu, 21 May 2026 12:32:19 +0100
Subject: [PATCH 1/2] [Flang][OpenMP] Allow workdistribute inside 'target
 teams'

Currently, a `workdistribute` construct nested inside of a combined
`target teams` is incorrectly reported as an error. This patch fixes
that.
---
 flang/lib/Semantics/check-omp-structure.cpp   |  2 +-
 .../Semantics/OpenMP/workdistribute05.f90     | 25 +++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Semantics/OpenMP/workdistribute05.f90

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 512de68d63e7e..2e6c0720c77ea 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1138,7 +1138,7 @@ void OmpStructureChecker::Enter(const parser::OmpBlockConstruct &x) {
           "directives outside of the TEAMS construct"_err_en_US);
     }
     if (GetContext().directive == llvm::omp::Directive::OMPD_workdistribute &&
-        GetContextParent().directive != llvm::omp::Directive::OMPD_teams) {
+        !llvm::omp::bottomTeamsSet.test(GetContextParent().directive)) {
       context_.Say(x.BeginDir().DirName().source,
           "%s region can only be strictly nested within TEAMS region"_err_en_US,
           ContextDirectiveAsFortran());
diff --git a/flang/test/Semantics/OpenMP/workdistribute05.f90 b/flang/test/Semantics/OpenMP/workdistribute05.f90
new file mode 100644
index 0000000000000..3d23153fa5078
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/workdistribute05.f90
@@ -0,0 +1,25 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=60
+! OpenMP Version 6.0
+! workdistribute Construct
+! Make sure that standalone workdistribute doesn't trigger errors when used in
+! supported contexts.
+
+subroutine teams_workdistribute()
+  use iso_fortran_env
+  real(kind=real32) :: a
+  !$omp teams
+  !$omp workdistribute
+  a = 1
+  !$omp end workdistribute
+  !$omp end teams
+end subroutine teams_workdistribute
+
+subroutine target_teams_workdistribute()
+  use iso_fortran_env
+  real(kind=real32) :: a
+  !$omp target teams
+  !$omp workdistribute
+  a = 1
+  !$omp end workdistribute
+  !$omp end target teams
+end subroutine target_teams_workdistribute

>From a49a6f607e8de4d863e2842251336a60d1ac1eb7 Mon Sep 17 00:00:00 2001
From: Sergio Afonso <Sergio.AfonsoFumero at amd.com>
Date: Thu, 21 May 2026 13:30:25 +0100
Subject: [PATCH 2/2] simplify test

---
 flang/test/Semantics/OpenMP/workdistribute05.f90 | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/test/Semantics/OpenMP/workdistribute05.f90 b/flang/test/Semantics/OpenMP/workdistribute05.f90
index 3d23153fa5078..3c06bf4f1a4c9 100644
--- a/flang/test/Semantics/OpenMP/workdistribute05.f90
+++ b/flang/test/Semantics/OpenMP/workdistribute05.f90
@@ -5,8 +5,7 @@
 ! supported contexts.
 
 subroutine teams_workdistribute()
-  use iso_fortran_env
-  real(kind=real32) :: a
+  integer :: a
   !$omp teams
   !$omp workdistribute
   a = 1
@@ -15,8 +14,7 @@ subroutine teams_workdistribute()
 end subroutine teams_workdistribute
 
 subroutine target_teams_workdistribute()
-  use iso_fortran_env
-  real(kind=real32) :: a
+  integer :: a
   !$omp target teams
   !$omp workdistribute
   a = 1



More information about the flang-commits mailing list