Skip to content

Commit 3651ab6

Browse files
committed
[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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254141 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6319930 commit 3651ab6

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7901,6 +7901,10 @@ def note_omp_static_member_in_target : Note<
79017901
"mappable type cannot contain static members">;
79027902
def err_omp_threadprivate_in_map : Error<
79037903
"threadprivate variables are not allowed in map clause">;
7904+
def err_omp_wrong_ordered_loop_count : Error<
7905+
"the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause">;
7906+
def note_collapse_loop_count : Note<
7907+
"parameter of the 'collapse' clause">;
79047908
} // end of OpenMP category
79057909

79067910
let CategoryName = "Related Result Type Issue" in {

lib/Sema/SemaOpenMP.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3359,13 +3359,22 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
33593359
// Found 'collapse' clause - calculate collapse number.
33603360
llvm::APSInt Result;
33613361
if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext()))
3362-
NestedLoopCount += Result.getLimitedValue() - 1;
3362+
NestedLoopCount = Result.getLimitedValue();
33633363
}
33643364
if (OrderedLoopCountExpr) {
33653365
// Found 'ordered' clause - calculate collapse number.
33663366
llvm::APSInt Result;
3367-
if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext()))
3368-
NestedLoopCount += Result.getLimitedValue() - 1;
3367+
if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) {
3368+
if (Result.getLimitedValue() < NestedLoopCount) {
3369+
SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
3370+
diag::err_omp_wrong_ordered_loop_count)
3371+
<< OrderedLoopCountExpr->getSourceRange();
3372+
SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
3373+
diag::note_collapse_loop_count)
3374+
<< CollapseLoopCountExpr->getSourceRange();
3375+
}
3376+
NestedLoopCount = Result.getLimitedValue();
3377+
}
33693378
}
33703379
// This is helper routine for loop directives (e.g., 'for', 'simd',
33713380
// 'for simd', etc.).
@@ -5256,13 +5265,10 @@ ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E,
52565265
<< E->getSourceRange();
52575266
return ExprError();
52585267
}
5259-
if (CKind == OMPC_collapse) {
5260-
DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 +
5261-
Result.getExtValue());
5262-
} else if (CKind == OMPC_ordered) {
5263-
DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 +
5264-
Result.getExtValue());
5265-
}
5268+
if (CKind == OMPC_collapse)
5269+
DSAStack->setCollapseNumber(Result.getExtValue());
5270+
else if (CKind == OMPC_ordered)
5271+
DSAStack->setCollapseNumber(Result.getExtValue());
52665272
return ICE;
52675273
}
52685274

test/OpenMP/for_ordered_clause.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}
5252
#pragma omp for ordered(1)
5353
for (int i = ST; i < N; i++)
5454
argv[0][i] = argv[0][i] - argv[0][i - ST];
55+
#pragma omp for ordered(N-1) // expected-error 2 {{argument to 'ordered' clause must be a positive integer value}}
56+
for (int i = ST; i < N; i++)
57+
argv[0][i] = argv[0][i] - argv[0][i - ST];
5558
#pragma omp for ordered(N) // expected-error {{argument to 'ordered' clause must be a positive integer value}}
5659
for (T i = ST; i < N; i++)
5760
argv[0][i] = argv[0][i] - argv[0][i - ST];
5861
#pragma omp for ordered(2) // expected-note {{as specified in 'ordered' clause}}
5962
foo(); // expected-error {{expected 2 for loops after '#pragma omp for'}}
63+
#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}}
64+
for (int i = ST; i < N; i++)
65+
for (int j = ST; j < N; j++)
66+
for (int k = ST; k < N; k++)
67+
foo();
6068
return argc;
6169
}
6270

@@ -98,6 +106,14 @@ int main(int argc, char **argv) {
98106
foo();
99107
#pragma omp for ordered(2) // expected-note {{as specified in 'ordered' clause}}
100108
foo(); // expected-error {{expected 2 for loops after '#pragma omp for'}}
109+
#pragma omp for ordered(0) // expected-error {{argument to 'ordered' clause must be a positive integer value}}
110+
for (int i = 4; i < 12; i++)
111+
argv[0][i] = argv[0][i] - argv[0][i - 4];
112+
#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}}
113+
for (int i = 0; i < 10; i++)
114+
for (int j = 0; j < 11; j++)
115+
for (int k = 0; k < 12; k++)
116+
foo();
101117
// expected-note@+1 {{in instantiation of function template specialization 'tmain<int, char, 1, 0>' requested here}}
102118
return tmain<int, char, 1, 0>(argc, argv);
103119
}

0 commit comments

Comments
 (0)