Author: abataev
Date: Thu Nov 26 01:50:39 2015
New Revision: 254141

URL: http://llvm.org/viewvc/llvm-project?rev=254141&view=rev
Log:
[OPENMP 4.5] Fixed rules for 'ordered' clause.
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.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaOpenMP.cpp
    cfe/trunk/test/OpenMP/for_ordered_clause.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=254141&r1=254140&r2=254141&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Nov 26 01:50:39 
2015
@@ -7901,6 +7901,10 @@ def note_omp_static_member_in_target : N
   "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 {

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=254141&r1=254140&r2=254141&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Nov 26 01:50:39 2015
@@ -3359,13 +3359,22 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKin
     // 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::VerifyPositiveIntegerCo
         << 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;
 }
 

Modified: cfe/trunk/test/OpenMP/for_ordered_clause.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_ordered_clause.cpp?rev=254141&r1=254140&r2=254141&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/for_ordered_clause.cpp (original)
+++ cfe/trunk/test/OpenMP/for_ordered_clause.cpp Thu Nov 26 01:50:39 2015
@@ -52,11 +52,19 @@ T tmain(T argc, S **argv) {
 #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);
 }


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to