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

via flang-commits flang-commits at lists.llvm.org
Thu May 21 04:37:51 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Sergio Afonso (skatrak)

<details>
<summary>Changes</summary>

Currently, a `workdistribute` construct nested inside of a combined `target teams` is incorrectly reported as an error. This patch fixes that.

---
Full diff: https://github.com/llvm/llvm-project/pull/199006.diff


2 Files Affected:

- (modified) flang/lib/Semantics/check-omp-structure.cpp (+1-1) 
- (added) flang/test/Semantics/OpenMP/workdistribute05.f90 (+25) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list