[flang-commits] [flang] 7e04d1b - [flang][OpenMP] Improve check for LINEAR and ORDERED with argument (#228235)

via flang-commits flang-commits at lists.llvm.org
Fri Oct 2 05:42:45 PDT 2026


Author: Krzysztof Parzyszek
Date: 2026-10-02T07:42:37-05:00
New Revision: 7e04d1b56db2d7ca799df2951e0bd6a6dcc78f7f

URL: https://github.com/llvm/llvm-project/commit/7e04d1b56db2d7ca799df2951e0bd6a6dcc78f7f
DIFF: https://github.com/llvm/llvm-project/commit/7e04d1b56db2d7ca799df2951e0bd6a6dcc78f7f.diff

LOG: [flang][OpenMP] Improve check for LINEAR and ORDERED with argument (#228235)

The LINEAR clause is not allowed on a construct if an ORDERED clause
with an argument is present. The new message is clearer about the
argument to the ORDERED clause.

Added: 
    

Modified: 
    flang/lib/Semantics/check-omp-loop.cpp
    flang/lib/Semantics/check-omp-structure.cpp
    flang/test/Semantics/OpenMP/clause-validity01.f90
    flang/test/Semantics/OpenMP/linear-clause03.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index 1e5df80790452d..b6fb4148546379 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -746,15 +746,35 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Depth &x) {
 }
 
 void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {
+  llvm::omp::Version version{context_.langOptions().getOpenMPVersion()};
+  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
+
+    // ORDERED(n) cannot be present on composite directive with SIMD.
+    // Ref: [5.1:139:21]
     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());
+      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));
+    }
+
+    // If ORDERED(n) is present no LINEAR may be present.
+    // Ref: [5.2:94:28], [6.0:514:7-8] (expressed in a 
diff erent way).
+    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);
+      }
     }
   }
 }

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 09b6c6bc3449fb..c45ad61f73aba2 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -3814,9 +3814,6 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &x) {
           std::get<parser::OmpClause::Ordered>(clause->u)};
 
       if (orderedClause.v) {
-        CheckNotAllowedIfClause(
-            llvm::omp::Clause::OMPC_ordered, {llvm::omp::Clause::OMPC_linear});
-
         if (auto *clause2{FindClause(llvm::omp::Clause::OMPC_collapse)}) {
           const auto &collapseClause{
               std::get<parser::OmpClause::Collapse>(clause2->u)};

diff  --git a/flang/test/Semantics/OpenMP/clause-validity01.f90 b/flang/test/Semantics/OpenMP/clause-validity01.f90
index e65cb89b8be08e..a01f0cff43ccf3 100644
--- a/flang/test/Semantics/OpenMP/clause-validity01.f90
+++ b/flang/test/Semantics/OpenMP/clause-validity01.f90
@@ -217,7 +217,8 @@
      a = 3.14
   enddo
 
-  !ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive
+  !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: 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
   !ERROR: The list item 'a' specified without the REF 'linear-modifier' must be of INTEGER type
@@ -226,7 +227,7 @@
      a = 3.14
   enddo
 
-  !ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive
+  !ERROR: LINEAR clause is not allowed when ORDERED clause with an argument is present
   !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
   !$omp do ordered(1-1) linear(a)
@@ -420,7 +421,7 @@
 !                         simd-clause
 
   !$omp parallel
-  !ERROR: No ORDERED clause with a parameter can be specified on the DO SIMD directive
+  !ERROR: ORDERED clause with an argument is not allowed on a compound directive with SIMD as a constituent
   !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 5eb4f31537a746..df74c906c2b2f0 100644
--- a/flang/test/Semantics/OpenMP/linear-clause03.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause03.f90
@@ -14,13 +14,20 @@ subroutine f(x, y)
 contains
 
 subroutine g
-  integer :: i
-  !ERROR: Clause LINEAR is not allowed if clause ORDERED appears on the DO directive
+  integer :: i, j
+  !ERROR: LINEAR clause is not allowed when ORDERED clause with an argument is present
   !ERROR: Loop iteration variable with a predetermined data sharing attribute cannot appear in a LINEAR clause
   !$omp do ordered(1) linear(i)
   !BECAUSE: 'i' is an iteration variable of an affected loop
   do i = 1, 10
   end do
+
+  j = 10
+  !This is ok
+  !$omp do ordered collapse(1) linear(j)
+  do i = 1, 10
+    j = j + 1
+  end do
 end
 
 subroutine h


        


More information about the flang-commits mailing list