[flang-commits] [flang] [flang][OpenMP] Loop IVs inside TEAMS are predetermined private in 5.2+ (PR #185958)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Thu Mar 12 04:22:12 PDT 2026
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/185958
>From 6feee433f8cdb58b0ba12b55554bac0386011cb6 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Wed, 11 Mar 2026 14:17:47 -0500
Subject: [PATCH 1/4] [flang][OpenMP] Loop IVs inside TEAMS are predetermined
private in 5.2+
Mark the induction variables of loops in a TEAMS construct as predetermined
private when OpenMP version is 5.2 or later.
---
flang/lib/Semantics/resolve-directives.cpp | 6 ++++
flang/test/Semantics/OpenMP/resolve07.f90 | 41 ++++++++++++++++++++++
2 files changed, 47 insertions(+)
create mode 100644 flang/test/Semantics/OpenMP/resolve07.f90
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index c8ffa22d6bb5f..0a78562b9d731 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2041,6 +2041,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
const parser::Name &iv) {
+ unsigned version{context_.langOptions().OpenMPVersion};
// Find the parallel or task generating construct enclosing the
// sequential loop.
auto targetIt{dirContext_.rbegin()};
@@ -2052,6 +2053,11 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
llvm::omp::taskGeneratingSet.test(targetIt->directive)) {
break;
}
+ if (version >= 52) {
+ if (llvm::omp::allTeamsSet.test(targetIt->directive)) {
+ break;
+ }
+ }
}
if (IsLocalInsideScope(*iv.symbol, targetIt->scope)) {
return;
diff --git a/flang/test/Semantics/OpenMP/resolve07.f90 b/flang/test/Semantics/OpenMP/resolve07.f90
new file mode 100644
index 0000000000000..f329446034cfe
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/resolve07.f90
@@ -0,0 +1,41 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=52
+
+subroutine f00
+ implicit none
+
+ integer, parameter :: n = 1024
+ integer :: i, j, k, array(n, n, n)
+
+ !The i and j are predermined private as loop induction variables nested
+ !in a teams construct.
+ !$omp target teams distribute default(none) shared(array)
+ do i = 1, n
+ do j = 1, n
+ !i and j are shared in parallel
+ !$omp parallel do shared(array)
+ do k = 1, n
+ array(i, j, k) = i + j + k
+ enddo
+ enddo
+ enddo
+end
+
+subroutine f01
+ implicit none
+
+ integer, parameter :: n = 1024
+ integer :: i, j, k, array(n, n, n)
+
+ !$omp target teams distribute default(none) shared(array)
+ do i = 1, n
+ do j = 1, n
+ !$omp parallel do default(none) shared(array)
+ do k = 1, n
+ !ERROR: The DEFAULT(NONE) clause requires that 'i' must be listed in a data-sharing attribute clause
+ !ERROR: The DEFAULT(NONE) clause requires that 'j' must be listed in a data-sharing attribute clause
+ array(i, j, k) = i + j + k
+ enddo
+ enddo
+ enddo
+end
+
>From 226779546c42a19dbfd2e4eca55b3c0f834ab783 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Wed, 11 Mar 2026 14:24:21 -0500
Subject: [PATCH 2/4] Predermined -> predetermined
I can't spell predetermined in a single attempt.
---
flang/test/Semantics/OpenMP/resolve07.f90 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/test/Semantics/OpenMP/resolve07.f90 b/flang/test/Semantics/OpenMP/resolve07.f90
index f329446034cfe..84224395ca884 100644
--- a/flang/test/Semantics/OpenMP/resolve07.f90
+++ b/flang/test/Semantics/OpenMP/resolve07.f90
@@ -6,7 +6,7 @@ subroutine f00
integer, parameter :: n = 1024
integer :: i, j, k, array(n, n, n)
- !The i and j are predermined private as loop induction variables nested
+ !The i and j are predetermined private as loop induction variables nested
!in a teams construct.
!$omp target teams distribute default(none) shared(array)
do i = 1, n
>From 1f662084e2ea95edf744d7d73042ae233ea4e2c6 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 12 Mar 2026 06:01:56 -0500
Subject: [PATCH 3/4] Update comment
---
flang/lib/Semantics/resolve-directives.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 0a78562b9d731..e53fd485ee8d4 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2042,7 +2042,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
const parser::Name &iv) {
unsigned version{context_.langOptions().OpenMPVersion};
- // Find the parallel or task generating construct enclosing the
+ // Find the parallel, teams or task generating construct enclosing the
// sequential loop.
auto targetIt{dirContext_.rbegin()};
for (;; ++targetIt) {
>From 5fc04b976db12fa063c2ed1c85f0fc8711f804cc Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 12 Mar 2026 06:21:38 -0500
Subject: [PATCH 4/4] Use test_symbols.py instead of test_errors.py
---
flang/test/Semantics/OpenMP/resolve07.f90 | 40 +++++++++++------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/flang/test/Semantics/OpenMP/resolve07.f90 b/flang/test/Semantics/OpenMP/resolve07.f90
index 84224395ca884..06370e2293182 100644
--- a/flang/test/Semantics/OpenMP/resolve07.f90
+++ b/flang/test/Semantics/OpenMP/resolve07.f90
@@ -1,41 +1,41 @@
-! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=52
+!RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp -fopenmp-version=52
+!DEF: /f00 (Subroutine) Subprogram
subroutine f00
implicit none
+!DEF: /f00/n PARAMETER ObjectEntity INTEGER(4)
integer, parameter :: n = 1024
- integer :: i, j, k, array(n, n, n)
+ !DEF: /f00/i ObjectEntity INTEGER(4)
+ !DEF: /f00/j ObjectEntity INTEGER(4)
+ !DEF: /f00/k ObjectEntity INTEGER(4)
+ !DEF: /f00/array ObjectEntity INTEGER(4)
+ !REF: /f00/n
+ integer i, j, k, array(n, n, n)
!The i and j are predetermined private as loop induction variables nested
!in a teams construct.
!$omp target teams distribute default(none) shared(array)
+!DEF: /f00/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
+!REF: /f00/n
do i = 1, n
+!DEF: /f00/OtherConstruct1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
+!REF: /f00/n
do j = 1, n
!i and j are shared in parallel
!$omp parallel do shared(array)
+!DEF: /f00/OtherConstruct1/OtherConstruct1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
+!REF: /f00/n
do k = 1, n
+!DEF: /f00/OtherConstruct1/OtherConstruct1/array (OmpShared, OmpExplicit) HostAssoc INTEGER(4)
+!DEF: /f00/OtherConstruct1/OtherConstruct1/i (OmpShared) HostAssoc INTEGER(4)
+!DEF: /f00/OtherConstruct1/OtherConstruct1/j (OmpShared) HostAssoc INTEGER(4)
+!REF: /f00/OtherConstruct1/OtherConstruct1/k
array(i, j, k) = i + j + k
enddo
enddo
enddo
-end
+end subroutine
-subroutine f01
- implicit none
-
- integer, parameter :: n = 1024
- integer :: i, j, k, array(n, n, n)
- !$omp target teams distribute default(none) shared(array)
- do i = 1, n
- do j = 1, n
- !$omp parallel do default(none) shared(array)
- do k = 1, n
- !ERROR: The DEFAULT(NONE) clause requires that 'i' must be listed in a data-sharing attribute clause
- !ERROR: The DEFAULT(NONE) clause requires that 'j' must be listed in a data-sharing attribute clause
- array(i, j, k) = i + j + k
- enddo
- enddo
- enddo
-end
More information about the flang-commits
mailing list