[flang-commits] [flang] [flang][OpenMP] Improve checks of ORDERED clause (PR #226472)
via flang-commits
flang-commits at lists.llvm.org
Fri Sep 25 05:47:38 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
@llvm/pr-subscribers-flang-openmp
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
Make the checks version-sensitive.
This adds some diagnostics that effectively replace existing ones. The old ones will be removed in a later PR, for the time being both will be shown.
---
Full diff: https://github.com/llvm/llvm-project/pull/226472.diff
4 Files Affected:
- (modified) flang/lib/Semantics/check-omp-loop.cpp (+39-6)
- (modified) flang/test/Semantics/OpenMP/clause-validity01.f90 (+3-1)
- (modified) flang/test/Semantics/OpenMP/linear-clause03.f90 (+1)
- (modified) flang/test/Semantics/OpenMP/ordered03.f90 (+1)
``````````diff
diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index 1e5df80790452..099caaf64af73 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -746,17 +746,50 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Depth &x) {
}
void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {
+ llvm::omp::Version version{context_.langOptions().getOpenMPVersion()};
+ auto leafs{llvm::omp::getLeafConstructsOrSelf(dirStack_.back()->DirId())};
+ parser::CharBlock source{GetContext().clauseSource};
+ std::string clauseName{
+ parser::omp::GetUpperName(llvm::omp::Clause::OMPC_ordered, version)};
+
// the parameter of ordered clause is optional
if (const auto &expr{x.v}) {
RequiresConstantPositiveParameter(llvm::omp::Clause::OMPC_ordered, *expr);
- // 2.8.3 Loop SIMD Construct Restriction
- if (llvm::omp::allDoSimdSet.test(GetContext().directive)) {
- context_.Say(GetContext().clauseSource,
- "No ORDERED clause with a parameter can be specified "
- "on the %s directive"_err_en_US,
- ContextDirectiveAsFortran());
+
+ // 5.1-: ORDERED(n) cannot be present on composite directive with SIMD.
+ if (version <= 51) {
+ if (llvm::is_contained(leafs, llvm::omp::Directive::OMPD_simd)) {
+ context_.Say(source,
+ "%s clause with an argument is not allowed on a compound directive with %s as a constituent"_err_en_US,
+ clauseName,
+ parser::omp::GetUpperName(
+ llvm::omp::Directive::OMPD_simd, version));
+ }
+ }
+ // 5.2-: If ORDERED(n), no LINEAR may be present.
+ if (version <= 52) {
+ for (const parser::OmpClause &clause : dirStack_.back()->Clauses().v) {
+ llvm::omp::Clause clauseId{clause.Id()};
+ if (clauseId == llvm::omp::Clause::OMPC_linear) {
+ context_
+ .Say(clause.source,
+ "%s clause is not allowed when %s clause with an argument is present"_err_en_US,
+ parser::omp::GetUpperName(clauseId, version), clauseName)
+ .Attach(source, "%s clause specified here"_en_US, clauseName);
+ }
+ }
}
}
+
+ if (llvm::is_contained(leafs, llvm::omp::OMPD_distribute)) {
+ // ORDERED is not allowed on DISTRIBUTE, so there have to be multiple leafs.
+ assert(leafs.size() > 1 && "Unexpected directive");
+ context_.Say(GetContext().clauseSource,
+ "%s clause is not allowed on a compound directive with %s as a constituent"_err_en_US,
+ clauseName,
+ parser::omp::GetUpperName(
+ llvm::omp::Directive::OMPD_distribute, version));
+ }
}
void OmpStructureChecker::Enter(const parser::OmpClause::Linear &x) {
diff --git a/flang/test/Semantics/OpenMP/clause-validity01.f90 b/flang/test/Semantics/OpenMP/clause-validity01.f90
index e65cb89b8be08..e31651a343f3b 100644
--- a/flang/test/Semantics/OpenMP/clause-validity01.f90
+++ b/flang/test/Semantics/OpenMP/clause-validity01.f90
@@ -217,6 +217,8 @@
a = 3.14
enddo
+ !ERROR: LINEAR clause is not allowed when ORDERED clause with an argument is present
+ !ERROR: LINEAR clause is not allowed when ORDERED clause with an argument is present
!ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive
!ERROR: The parameter of the ORDERED clause must be a constant positive integer expression
!ERROR: 'b' appears in more than one data-sharing clause on the same OpenMP directive
@@ -226,6 +228,7 @@
a = 3.14
enddo
+ !ERROR: LINEAR clause is not allowed when ORDERED clause with an argument is present
!ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive
!ERROR: The parameter of the ORDERED clause must be a constant positive integer expression
!ERROR: The list item 'a' specified without the REF 'linear-modifier' must be of INTEGER type
@@ -420,7 +423,6 @@
! simd-clause
!$omp parallel
- !ERROR: No ORDERED clause with a parameter can be specified on the DO SIMD directive
!ERROR: NOGROUP clause is not allowed on DO SIMD directive
!$omp do simd ordered(2) NOGROUP nowait
do i = 1, N
diff --git a/flang/test/Semantics/OpenMP/linear-clause03.f90 b/flang/test/Semantics/OpenMP/linear-clause03.f90
index 5eb4f31537a74..7f6e3349ca0d0 100644
--- a/flang/test/Semantics/OpenMP/linear-clause03.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause03.f90
@@ -15,6 +15,7 @@ subroutine f(x, y)
subroutine g
integer :: i
+ !ERROR: LINEAR clause is not allowed when ORDERED clause with an argument is present
!ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive
!ERROR: Loop iteration variable with a predetermined data sharing attribute cannot appear in a LINEAR clause
!$omp do ordered(1) linear(i)
diff --git a/flang/test/Semantics/OpenMP/ordered03.f90 b/flang/test/Semantics/OpenMP/ordered03.f90
index ca5e3bf151b41..691cc7aec90cc 100644
--- a/flang/test/Semantics/OpenMP/ordered03.f90
+++ b/flang/test/Semantics/OpenMP/ordered03.f90
@@ -52,6 +52,7 @@ subroutine sub1()
end do
!$omp end target parallel do
+ !ERROR: ORDERED clause is not allowed on a compound directive with DISTRIBUTE as a constituent
!ERROR: ORDERED clause is not allowed on TARGET TEAMS DISTRIBUTE PARALLEL DO directive
!$omp target teams distribute parallel do ordered(1)
do i = 1, N
``````````
</details>
https://github.com/llvm/llvm-project/pull/226472
More information about the flang-commits
mailing list