[flang-commits] [flang] [Flang][OpenMP] Allow `parallel loop` inside of `teams` (PR #210679)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Mon Jul 20 03:42:26 PDT 2026


https://github.com/skatrak created https://github.com/llvm/llvm-project/pull/210679

A missing `parallel_loop` directive in the `nestedTeamsAllowedSet` currently causes code like the following to report a semantics issue:
```f90
!$omp teams
  !$omp parallel loop
  do i=1, 10
  end do
!$omp end teams
```
This patch makes sure to accept it, since `parallel` is an allowed construct to be immediately nested inside of `teams`, even when combined with another construct.

>From 6062a36a1b2712a9012e56baf93fa6df0954b5ba Mon Sep 17 00:00:00 2001
From: Sergio Afonso <Sergio.AfonsoFumero at amd.com>
Date: Mon, 20 Jul 2026 11:37:20 +0100
Subject: [PATCH] [Flang][OpenMP] Allow `parallel loop` inside of `teams`

A missing `parallel_loop` directive in the `nestedTeamsAllowedSet`
currently causes code like the following to report a semantics issue:
```f90
!$omp teams
  !$omp parallel loop
  do i=1, 10
  end do
!$omp end teams
```
This patch makes sure to accept it, since `parallel` is an allowed
construct to be immediately nested inside of `teams`, even when combined
with another construct.
---
 .../flang/Semantics/openmp-directive-sets.h   |  1 +
 flang/test/Semantics/OpenMP/teams_loop.f90    | 37 +++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 flang/test/Semantics/OpenMP/teams_loop.f90

diff --git a/flang/include/flang/Semantics/openmp-directive-sets.h b/flang/include/flang/Semantics/openmp-directive-sets.h
index b99dd8fe07204..ab1eb36976380 100644
--- a/flang/include/flang/Semantics/openmp-directive-sets.h
+++ b/flang/include/flang/Semantics/openmp-directive-sets.h
@@ -402,6 +402,7 @@ static const OmpDirectiveSet nestedTeamsAllowedSet{
     Directive::OMPD_parallel,
     Directive::OMPD_parallel_do,
     Directive::OMPD_parallel_do_simd,
+    Directive::OMPD_parallel_loop,
     Directive::OMPD_parallel_master,
     Directive::OMPD_parallel_master_taskloop,
     Directive::OMPD_parallel_master_taskloop_simd,
diff --git a/flang/test/Semantics/OpenMP/teams_loop.f90 b/flang/test/Semantics/OpenMP/teams_loop.f90
new file mode 100644
index 0000000000000..1d95f438a9177
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/teams_loop.f90
@@ -0,0 +1,37 @@
+! RUN: %flang_fc1 -fopenmp -fsyntax-only %s
+
+! Test that various ways of nesting combined and standalone `loop` constructs
+! inside of `teams` are accepted.
+
+subroutine test()
+  implicit none
+  integer :: i
+
+  !$omp teams
+  !$omp parallel loop
+  do i=1, 10
+    call foo()
+  end do
+  !$omp end teams
+
+  !$omp target teams
+  !$omp parallel loop
+  do i=1, 10
+    call foo()
+  end do
+  !$omp end target teams
+
+  !$omp target teams
+  !$omp loop
+  do i=1, 10
+    call foo()
+  end do
+  !$omp end target teams
+
+  !$omp teams
+  !$omp loop
+  do i=1, 10
+    call foo()
+  end do
+  !$omp end teams
+end subroutine



More information about the flang-commits mailing list