[flang-commits] [flang] [flang][OpenMP] Don't allow DO CONCURRENT inside of a loop nest (PR #144506)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Tue Jun 17 08:28:42 PDT 2025
https://github.com/tblah updated https://github.com/llvm/llvm-project/pull/144506
>From 3649ab11c52499a80146542cfd5fbed9260b2627 Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Tue, 17 Jun 2025 11:16:51 +0000
Subject: [PATCH 1/2] [flang][OpenMP] Don't allow DO CONCURRENT inside of a
loop nest
I don't think DO CONCURRENT fits the definition of a Canonical Loop Nest
(OpenMP 6.0 section 6.4.1).
Fixes #144178
---
flang/lib/Semantics/resolve-directives.cpp | 6 ++++++
.../Lower/OpenMP/Todo/omp-doconcurrent.f90 | 10 ----------
.../OpenMP/do-concurrent-collapse.f90 | 19 +++++++++++++++++++
3 files changed, 25 insertions(+), 10 deletions(-)
delete mode 100644 flang/test/Lower/OpenMP/Todo/omp-doconcurrent.f90
create mode 100644 flang/test/Semantics/OpenMP/do-concurrent-collapse.f90
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index b5f8667fe36f2..b6ff7e77ba3fd 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1952,6 +1952,12 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t)};
if (outer.has_value()) {
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0; --level) {
+ if (loop->IsDoConcurrent()) {
+ auto &stmt =
+ std::get<parser::Statement<parser::NonLabelDoStmt>>(loop->t);
+ context_.Say(stmt.source,
+ "DO CONCURRENT loops cannot form part of a loop nest."_err_en_US);
+ }
// go through all the nested do-loops and resolve index variables
const parser::Name *iv{GetLoopIndex(*loop)};
if (iv) {
diff --git a/flang/test/Lower/OpenMP/Todo/omp-doconcurrent.f90 b/flang/test/Lower/OpenMP/Todo/omp-doconcurrent.f90
deleted file mode 100644
index a6d70fa445928..0000000000000
--- a/flang/test/Lower/OpenMP/Todo/omp-doconcurrent.f90
+++ /dev/null
@@ -1,10 +0,0 @@
-! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
-! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
-
-! CHECK: not yet implemented: Do Concurrent in Worksharing loop construct
-subroutine sb()
- !$omp do
- do concurrent(i=1:10)
- print *, i
- end do
-end subroutine
diff --git a/flang/test/Semantics/OpenMP/do-concurrent-collapse.f90 b/flang/test/Semantics/OpenMP/do-concurrent-collapse.f90
new file mode 100644
index 0000000000000..71e1928e1f245
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/do-concurrent-collapse.f90
@@ -0,0 +1,19 @@
+!RUN: %python %S/../test_errors.py %s %flang -fopenmp
+
+integer :: i, j
+!$omp parallel do collapse(2)
+do i = 1, 1
+ ! ERROR: DO CONCURRENT loops cannot form part of a loop nest.
+ do concurrent (j = 1:2)
+ print *, j
+ end do
+end do
+
+!$omp parallel do
+do i = 1, 1
+ ! This should not lead to an error because it is not part of a loop nest:
+ do concurrent (j = 1:2)
+ print *, j
+ end do
+end do
+end
>From ab3fba8533682774bb752d0656e3e8c716ec5eba Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Tue, 17 Jun 2025 15:27:08 +0000
Subject: [PATCH 2/2] Allow do concurrent in loop constructs, but not loop
nests
---
flang/lib/Semantics/resolve-directives.cpp | 3 ++-
flang/test/Lower/OpenMP/Todo/omp-doconcurrent.f90 | 10 ++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Lower/OpenMP/Todo/omp-doconcurrent.f90
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index b6ff7e77ba3fd..05568cc0ba0ae 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1952,7 +1952,8 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t)};
if (outer.has_value()) {
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0; --level) {
- if (loop->IsDoConcurrent()) {
+ // DO CONCURRENT is allowed for loop constructs but not loop nests
+ if (loop->IsDoConcurrent() && GetContext().associatedLoopLevel != 1) {
auto &stmt =
std::get<parser::Statement<parser::NonLabelDoStmt>>(loop->t);
context_.Say(stmt.source,
diff --git a/flang/test/Lower/OpenMP/Todo/omp-doconcurrent.f90 b/flang/test/Lower/OpenMP/Todo/omp-doconcurrent.f90
new file mode 100644
index 0000000000000..a6d70fa445928
--- /dev/null
+++ b/flang/test/Lower/OpenMP/Todo/omp-doconcurrent.f90
@@ -0,0 +1,10 @@
+! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
+! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
+
+! CHECK: not yet implemented: Do Concurrent in Worksharing loop construct
+subroutine sb()
+ !$omp do
+ do concurrent(i=1:10)
+ print *, i
+ end do
+end subroutine
More information about the flang-commits
mailing list