]> granicus.if.org Git - clang/commitdiff
[OPENMP 4.5] Fixed rules for 'ordered' clause.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 26 Nov 2015 07:50:39 +0000 (07:50 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 26 Nov 2015 07:50:39 +0000 (07:50 +0000)
According to OpenMP 4.5 the parameter of 'ordered' clause must be greater than or equal to the parameter of 'collapse' clause. Patch adds this rule.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254141 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaOpenMP.cpp
test/OpenMP/for_ordered_clause.cpp

index 9585110f96739611eba2c02be2edf3a72df027fe..ece71d3be22b57fd1ab12d9e62f2ddcc36e4615e 100644 (file)
@@ -7901,6 +7901,10 @@ def note_omp_static_member_in_target : Note<
   "mappable type cannot contain static members">;
 def err_omp_threadprivate_in_map : Error<
   "threadprivate variables are not allowed in map clause">;
+def err_omp_wrong_ordered_loop_count : Error<
+  "the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause">;
+def note_collapse_loop_count : Note<
+  "parameter of the 'collapse' clause">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {
index 079f87aa868e7f2fd92e1b47755cc41b4867a83a..3392e53d5144cb4f132ec4d0cf45917c04caf0ca 100644 (file)
@@ -3359,13 +3359,22 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
     // Found 'collapse' clause - calculate collapse number.
     llvm::APSInt Result;
     if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext()))
-      NestedLoopCount += Result.getLimitedValue() - 1;
+      NestedLoopCount = Result.getLimitedValue();
   }
   if (OrderedLoopCountExpr) {
     // Found 'ordered' clause - calculate collapse number.
     llvm::APSInt Result;
-    if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext()))
-      NestedLoopCount += Result.getLimitedValue() - 1;
+    if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) {
+      if (Result.getLimitedValue() < NestedLoopCount) {
+        SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
+                     diag::err_omp_wrong_ordered_loop_count)
+            << OrderedLoopCountExpr->getSourceRange();
+        SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
+                     diag::note_collapse_loop_count)
+            << CollapseLoopCountExpr->getSourceRange();
+      }
+      NestedLoopCount = Result.getLimitedValue();
+    }
   }
   // This is helper routine for loop directives (e.g., 'for', 'simd',
   // 'for simd', etc.).
@@ -5256,13 +5265,10 @@ ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E,
         << E->getSourceRange();
     return ExprError();
   }
-  if (CKind == OMPC_collapse) {
-    DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 +
-                                Result.getExtValue());
-  } else if (CKind == OMPC_ordered) {
-    DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 +
-                                Result.getExtValue());
-  }
+  if (CKind == OMPC_collapse)
+    DSAStack->setCollapseNumber(Result.getExtValue());
+  else if (CKind == OMPC_ordered)
+    DSAStack->setCollapseNumber(Result.getExtValue());
   return ICE;
 }
 
index 5b08021587356a47ebfc32e536b2a1afe132142b..f28731e47706eb2284dc99aa6c979845c62a6b3a 100644 (file)
@@ -52,11 +52,19 @@ T tmain(T argc, S **argv) {                   //expected-note 2 {{declared here}
 #pragma omp for ordered(1)
   for (int i = ST; i < N; i++)
     argv[0][i] = argv[0][i] - argv[0][i - ST];
+#pragma omp for ordered(N-1) // expected-error 2 {{argument to 'ordered' clause must be a positive integer value}}
+  for (int i = ST; i < N; i++)
+    argv[0][i] = argv[0][i] - argv[0][i - ST];
 #pragma omp for ordered(N) // expected-error {{argument to 'ordered' clause must be a positive integer value}}
   for (T i = ST; i < N; i++)
     argv[0][i] = argv[0][i] - argv[0][i - ST];
 #pragma omp for ordered(2) // expected-note {{as specified in 'ordered' clause}}
   foo();                    // expected-error {{expected 2 for loops after '#pragma omp for'}}
+#pragma omp for ordered(N) collapse(N + 2) // expected-error {{the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause}} expected-note {{parameter of the 'collapse' clause}} expected-error {{argument to 'ordered' clause must be a positive integer value}}
+  for (int i = ST; i < N; i++)
+    for (int j = ST; j < N; j++)
+      for (int k = ST; k < N; k++)
+        foo();
   return argc;
 }
 
@@ -98,6 +106,14 @@ int main(int argc, char **argv) {
   foo();
 #pragma omp for ordered(2) // expected-note {{as specified in 'ordered' clause}}
   foo();                    // expected-error {{expected 2 for loops after '#pragma omp for'}}
+#pragma omp for ordered(0)              // expected-error {{argument to 'ordered' clause must be a positive integer value}}
+  for (int i = 4; i < 12; i++)
+    argv[0][i] = argv[0][i] - argv[0][i - 4];
+#pragma omp for ordered(2) collapse(3) // expected-error {{the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause}} expected-note {{parameter of the 'collapse' clause}}
+  for (int i = 0; i < 10; i++)
+    for (int j = 0; j < 11; j++)
+      for (int k = 0; k < 12; k++)
+        foo();
   // expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, 1, 0>' requested here}}
   return tmain<int, char, 1, 0>(argc, argv);
 }