Skip to content

Commit

Permalink
[OPENMP] Do not allow variables to be first|last-privates in
Browse files Browse the repository at this point in the history
distribute directives.

OpenMP standard does not allow to mark the variables as firstprivate and lastprivate at the same time in distribute-based directives. Patch fixes this problem.

llvm-svn: 319560
  • Loading branch information
alexey-bataev committed Dec 1, 2017
1 parent 8d5e469 commit b358f99
Show file tree
Hide file tree
Showing 40 changed files with 160 additions and 102 deletions.
15 changes: 5 additions & 10 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9146,7 +9146,8 @@ OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
// A list item may appear in a firstprivate or lastprivate clause but not
// both.
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate &&
(CurrDir == OMPD_distribute || DVar.CKind != OMPC_lastprivate) &&
(isOpenMPDistributeDirective(CurrDir) ||
DVar.CKind != OMPC_lastprivate) &&
DVar.RefExpr) {
Diag(ELoc, diag::err_omp_wrong_dsa)
<< getOpenMPClauseName(DVar.CKind)
Expand Down Expand Up @@ -9240,14 +9241,7 @@ OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
// OpenMP 4.5 [2.15.5.1, Restrictions, p.3]
// A list item cannot appear in both a map clause and a data-sharing
// attribute clause on the same construct
if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel ||
CurrDir == OMPD_target_teams ||
CurrDir == OMPD_target_teams_distribute ||
CurrDir == OMPD_target_teams_distribute_parallel_for ||
CurrDir == OMPD_target_teams_distribute_parallel_for_simd ||
CurrDir == OMPD_target_teams_distribute_simd ||
CurrDir == OMPD_target_parallel_for_simd ||
CurrDir == OMPD_target_parallel_for) {
if (isOpenMPTargetExecutionDirective(CurrDir)) {
OpenMPClauseKind ConflictKind;
if (DSAStack->checkMappableExprComponentListsForDecl(
VD, /*CurrentRegionOnly=*/true,
Expand Down Expand Up @@ -9407,7 +9401,8 @@ OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList,
// both.
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false);
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate &&
(CurrDir == OMPD_distribute || DVar.CKind != OMPC_firstprivate) &&
(isOpenMPDistributeDirective(CurrDir) ||
DVar.CKind != OMPC_firstprivate) &&
(DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) {
Diag(ELoc, diag::err_omp_wrong_dsa)
<< getOpenMPClauseName(DVar.CKind)
Expand Down
6 changes: 3 additions & 3 deletions clang/test/OpenMP/distribute_parallel_for_ast_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ T tmain(T argc) {
// CHECK-NEXT: a = 2;
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) dist_schedule(static,N)
#pragma omp distribute parallel for private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) schedule(static, N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) dist_schedule(static,N)
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int j = 0; j < 2; ++j)
Expand All @@ -93,8 +93,8 @@ T tmain(T argc) {
for (int j = 0; j < 2; ++j)
for (int j = 0; j < 2; ++j)
for (int j = 0; j < 2; ++j)
a++;
// CHECK: #pragma omp distribute parallel for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) dist_schedule(static, N)
a++;
// CHECK: #pragma omp distribute parallel for private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) schedule(static, N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) dist_schedule(static, N)
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
// CHECK-NEXT: for (int j = 0; j < 2; ++j)
// CHECK-NEXT: for (int j = 0; j < 2; ++j)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class S4 {
};
class S5 {
int a;
S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
S5(const S5 &s5) : a(s5.a) {} // expected-note 2 {{implicitly declared private here}}

public:
S5() : a(0) {}
S5(int v) : a(v) {}
};
class S6 {
int a;
S6() : a(0) {}
S6() : a(0) {} // expected-note {{implicitly declared private here}}

public:
S6(const S6 &s6) : a(s6.a) {}
Expand Down Expand Up @@ -150,9 +150,10 @@ int foomain(int argc, char **argv) {
#pragma omp distribute parallel for firstprivate(i)
for (int k = 0; k < argc; ++k)
++k;
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
#pragma omp distribute parallel for lastprivate(g) firstprivate(g)
for (i = 0; i < argc; ++i)
foo();
#pragma omp parallel private(i)
Expand Down Expand Up @@ -314,14 +315,16 @@ int main(int argc, char **argv) {
#pragma omp distribute parallel for firstprivate(j)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
#pragma omp distribute parallel for lastprivate(g) firstprivate(g)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for lastprivate(n) firstprivate(n) // OK
#pragma omp distribute parallel for lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp parallel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const S2 b;
const S2 ba[5];
class S3 {
int a;
S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
S3 &operator=(const S3 &s3); // expected-note {{implicitly declared private here}}

public:
S3() : a(0) {}
Expand All @@ -52,7 +52,7 @@ class S5 {
};
class S6 {
int a;
S6() : a(0) {}
S6() : a(0) {} // expected-note {{implicitly declared private here}}

public:
S6(const S6 &s6) : a(s6.a) {}
Expand Down Expand Up @@ -313,14 +313,16 @@ int main(int argc, char **argv) {
#pragma omp distribute parallel for lastprivate(j)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{firstprivate variable cannot be lastprivate}} expected-note@+3 {{defined as firstprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
#pragma omp distribute parallel for firstprivate(m) lastprivate(m)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for lastprivate(n) firstprivate(n) // OK
#pragma omp distribute parallel for lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}}
for (i = 0; i < argc; ++i)
foo();
static int si;
Expand Down
6 changes: 3 additions & 3 deletions clang/test/OpenMP/distribute_parallel_for_simd_ast_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ T tmain(T argc) {
// CHECK-NEXT: a = 2;
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) dist_schedule(static,N)
#pragma omp distribute parallel for simd private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) schedule(static, N) if (parallel :argc) num_threads(N) default(shared) shared(e) reduction(+ : h) dist_schedule(static,N)
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int j = 0; j < 2; ++j)
Expand All @@ -94,8 +94,8 @@ T tmain(T argc) {
for (int j = 0; j < 2; ++j)
for (int j = 0; j < 2; ++j)
for (int j = 0; j < 2; ++j)
a++;
// CHECK: #pragma omp distribute parallel for simd private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) dist_schedule(static, N)
a++;
// CHECK: #pragma omp distribute parallel for simd private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) schedule(static, N) if(parallel: argc) num_threads(N) default(shared) shared(e) reduction(+: h) dist_schedule(static, N)
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
// CHECK-NEXT: for (int j = 0; j < 2; ++j)
// CHECK-NEXT: for (int j = 0; j < 2; ++j)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class S4 {
};
class S5 {
int a;
S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
S5(const S5 &s5) : a(s5.a) {} // expected-note 2 {{implicitly declared private here}}

public:
S5() : a(0) {}
S5(int v) : a(v) {}
};
class S6 {
int a;
S6() : a(0) {}
S6() : a(0) {} // expected-note {{implicitly declared private here}}

public:
S6(const S6 &s6) : a(s6.a) {}
Expand Down Expand Up @@ -150,9 +150,10 @@ int foomain(int argc, char **argv) {
#pragma omp distribute parallel for simd firstprivate(i)
for (int k = 0; k < argc; ++k)
++k;
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
#pragma omp distribute parallel for simd lastprivate(g) firstprivate(g)
for (i = 0; i < argc; ++i)
foo();
#pragma omp parallel private(i)
Expand Down Expand Up @@ -314,14 +315,16 @@ int main(int argc, char **argv) {
#pragma omp distribute parallel for simd firstprivate(j)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
#pragma omp distribute parallel for simd lastprivate(g) firstprivate(g)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd lastprivate(n) firstprivate(n) // OK
#pragma omp distribute parallel for simd lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp parallel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const S2 b;
const S2 ba[5];
class S3 {
int a;
S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
S3 &operator=(const S3 &s3); // expected-note {{implicitly declared private here}}

public:
S3() : a(0) {}
Expand All @@ -52,7 +52,7 @@ class S5 {
};
class S6 {
int a;
S6() : a(0) {}
S6() : a(0) {} // expected-note {{implicitly declared private here}}

public:
S6(const S6 &s6) : a(s6.a) {}
Expand Down Expand Up @@ -313,14 +313,16 @@ int main(int argc, char **argv) {
#pragma omp distribute parallel for simd lastprivate(j)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{firstprivate variable cannot be lastprivate}} expected-note@+3 {{defined as firstprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
#pragma omp distribute parallel for simd firstprivate(m) lastprivate(m)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd lastprivate(n) firstprivate(n) // OK
#pragma omp distribute parallel for simd lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}}
for (i = 0; i < argc; ++i)
foo();
static int si;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class S {
int a;
S() : a(0) {}
S() : a(0) {} // expected-note {{implicitly declared private here}}

public:
S(int v) : a(v) {}
Expand Down Expand Up @@ -790,9 +790,10 @@ void test_loop_eh() {

void test_loop_firstprivate_lastprivate() {
S s(4);
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd lastprivate(s) firstprivate(s)
#pragma omp distribute parallel for simd lastprivate(s) firstprivate(s) // expected-error {{calling a private constructor of class 'S'}}
for (int i = 0; i < 16; ++i)
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,16 +851,19 @@ void test_firstprivate() {
;

int x, y, z;
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd lastprivate(x) firstprivate(x)
for (i = 0; i < 16; ++i)
;
// expected-error@+3 2 {{lastprivate variable cannot be firstprivate}} expected-note@+3 2 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd lastprivate(x, y) firstprivate(x, y)
for (i = 0; i < 16; ++i)
;
// expected-error@+3 3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute parallel for simd lastprivate(x, y, z) firstprivate(x, y, z)
Expand Down
4 changes: 2 additions & 2 deletions clang/test/OpenMP/distribute_simd_ast_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ T tmain(T argc) {

#pragma omp target
#pragma omp teams
#pragma omp distribute simd private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) reduction(+ : h) dist_schedule(static,N)
#pragma omp distribute simd private(argc, b), firstprivate(c, d), lastprivate(f) collapse(N) reduction(+ : h) dist_schedule(static,N)
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 10; ++k)
for (int m = 0; m < 10; ++m)
for (int n = 0; n < 10; ++n)
a++;
// CHECK: #pragma omp distribute simd private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) reduction(+: h) dist_schedule(static, N)
// CHECK: #pragma omp distribute simd private(argc,b) firstprivate(c,d) lastprivate(f) collapse(N) reduction(+: h) dist_schedule(static, N)
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
// CHECK-NEXT: for (int j = 0; j < 2; ++j)
// CHECK-NEXT: for (int k = 0; k < 10; ++k)
Expand Down
13 changes: 8 additions & 5 deletions clang/test/OpenMP/distribute_simd_firstprivate_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class S4 {
};
class S5 {
int a;
S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
S5(const S5 &s5) : a(s5.a) {} // expected-note 2 {{implicitly declared private here}}

public:
S5() : a(0) {}
S5(int v) : a(v) {}
};
class S6 {
int a;
S6() : a(0) {}
S6() : a(0) {} // expected-note {{implicitly declared private here}}

public:
S6(const S6 &s6) : a(s6.a) {}
Expand Down Expand Up @@ -150,9 +150,10 @@ int foomain(int argc, char **argv) {
#pragma omp distribute simd firstprivate(i)
for (int k = 0; k < argc; ++k)
++k;
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
#pragma omp distribute simd lastprivate(g) firstprivate(g)
for (i = 0; i < argc; ++i)
foo();
#pragma omp parallel private(i)
Expand Down Expand Up @@ -314,14 +315,16 @@ int main(int argc, char **argv) {
#pragma omp distribute simd firstprivate(j)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
#pragma omp distribute simd lastprivate(g) firstprivate(g)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute simd lastprivate(n) firstprivate(n) // OK
#pragma omp distribute simd lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp parallel
Expand Down
10 changes: 6 additions & 4 deletions clang/test/OpenMP/distribute_simd_lastprivate_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const S2 b;
const S2 ba[5];
class S3 {
int a;
S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
S3 &operator=(const S3 &s3); // expected-note {{implicitly declared private here}}

public:
S3() : a(0) {}
Expand All @@ -52,7 +52,7 @@ class S5 {
};
class S6 {
int a;
S6() : a(0) {}
S6() : a(0) {} // expected-note {{implicitly declared private here}}

public:
S6(const S6 &s6) : a(s6.a) {}
Expand Down Expand Up @@ -313,14 +313,16 @@ int main(int argc, char **argv) {
#pragma omp distribute simd lastprivate(j)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{firstprivate variable cannot be lastprivate}} expected-note@+3 {{defined as firstprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute simd firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
#pragma omp distribute simd firstprivate(m) lastprivate(m)
for (i = 0; i < argc; ++i)
foo();
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
#pragma omp target
#pragma omp teams
#pragma omp distribute simd lastprivate(n) firstprivate(n) // OK
#pragma omp distribute simd lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}}
for (i = 0; i < argc; ++i)
foo();
static int si;
Expand Down

0 comments on commit b358f99

Please sign in to comment.