[flang-commits] [flang] [Flang][OpenMP] Added diagnostic for ORDERED THREADS SIMD inside plain SIMD region (PR #205723)
Urvi Rav via flang-commits
flang-commits at lists.llvm.org
Thu Jul 9 02:31:56 PDT 2026
https://github.com/ravurvi20 updated https://github.com/llvm/llvm-project/pull/205723
>From b2992683d4fd433aab202a09199f05240477d49b Mon Sep 17 00:00:00 2001
From: Urvi Rav <urvi.rav20 at gmail.com>
Date: Thu, 25 Jun 2026 00:14:55 -0500
Subject: [PATCH 1/2] Added diagnostic for ORDERED THREADS SIMD inside plain
SIMD region
---
flang/lib/Semantics/check-omp-structure.cpp | 7 +++++++
flang/test/Semantics/OpenMP/ordered02.f90 | 19 +++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index d87b2f1983de6..ea7027d55953e 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1486,6 +1486,13 @@ void OmpStructureChecker::ChecksOnOrderedAsBlock() {
context_.Say(GetContext().directiveSource,
"An ORDERED directive with SIMD clause must be closely nested in a "
"SIMD or worksharing-loop SIMD region"_err_en_US);
+ } else if (CurrentDirectiveIsNested() &&
+ FindClause(llvm::omp::Clause::OMPC_simd) &&
+ FindClause(llvm::omp::Clause::OMPC_threads) && isNestedInSIMD &&
+ !isNestedInDoSIMD) {
+ context_.Say(GetContext().directiveSource,
+ "An ORDERED directive with SIMD and THREADS clauses must be closely "
+ "nested in a worksharing-loop SIMD region"_err_en_US);
}
if (isNestedInDo && (noOrderedClause || isOrderedClauseWithPara)) {
context_.Say(GetContext().directiveSource,
diff --git a/flang/test/Semantics/OpenMP/ordered02.f90 b/flang/test/Semantics/OpenMP/ordered02.f90
index ed320c82a9794..ad3e2b3428115 100644
--- a/flang/test/Semantics/OpenMP/ordered02.f90
+++ b/flang/test/Semantics/OpenMP/ordered02.f90
@@ -143,4 +143,23 @@ subroutine sub1()
!$omp end ordered
end do
!$omp end target parallel do
+
+ ! THREADS+SIMD inside a plain SIMD (not DO SIMD) region must be rejected
+ !$omp simd
+ do i = 1, N
+ !ERROR: An ORDERED directive with SIMD and THREADS clauses must be closely nested in a worksharing-loop SIMD region
+ !$omp ordered threads simd
+ arrayA(i) = foo(i)
+ !$omp end ordered
+ end do
+ !$omp end simd
+
+ ! THREADS+SIMD inside a DO SIMD region is valid
+ !$omp do simd ordered
+ do i = 1, N
+ !$omp ordered threads simd
+ arrayA(i) = foo(i)
+ !$omp end ordered
+ end do
+ !$omp end do simd
end
>From 2194a05764a56121972f514c0cd5bd59cdb4eb46 Mon Sep 17 00:00:00 2001
From: Urvi Rav <urvi.rav20 at gmail.com>
Date: Thu, 9 Jul 2026 04:31:00 -0500
Subject: [PATCH 2/2] Addressed comment-added regression test
---
flang/test/Semantics/OpenMP/ordered02.f90 | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/flang/test/Semantics/OpenMP/ordered02.f90 b/flang/test/Semantics/OpenMP/ordered02.f90
index ad3e2b3428115..649e008f7cb54 100644
--- a/flang/test/Semantics/OpenMP/ordered02.f90
+++ b/flang/test/Semantics/OpenMP/ordered02.f90
@@ -163,3 +163,20 @@ subroutine sub1()
end do
!$omp end do simd
end
+
+! No diagnostic when ORDERED THREADS SIMD is in a called routine (enclosing
+! DO SIMD region is not visible to the static checker).
+subroutine contains_ordered_threads_simd()
+ !$omp ordered threads simd
+ !$omp end ordered
+end subroutine
+
+subroutine sub2()
+ integer :: i, N = 10
+ external :: contains_ordered_threads_simd
+ !$omp do simd ordered
+ do i = 1, N
+ call contains_ordered_threads_simd()
+ end do
+ !$omp end do simd
+end subroutine
More information about the flang-commits
mailing list