From 571d9d84bb6665ec5a6925183a09c9dcb94ab94b Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Mon, 19 Jan 2015 05:20:46 +0000 Subject: [PATCH] [OPENMP] Disable copyprivate an nowait clauses in 'single' directive. The copyprivate clause must not be used with the nowait clause in single directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226429 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 4 ++++ lib/Sema/SemaOpenMP.cpp | 17 +++++++++++++++++ test/OpenMP/single_ast_print.cpp | 20 ++++++++++++++++---- test/OpenMP/single_copyprivate_messages.cpp | 2 ++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 9c097028b9..5b5528e4f7 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -7430,6 +7430,10 @@ def note_omp_nested_teams_construct_here : Note< "nested teams construct here">; def note_omp_nested_statement_here : Note< "%select{statement|directive}0 outside teams construct here">; +def err_omp_single_copyprivate_with_nowait : Error< + "the 'copyprivate' clause must not be used with the 'nowait' clause">; +def note_omp_nowait_clause_here : Note< + "'nowait' clause is here">; } // end of OpenMP category let CategoryName = "Related Result Type Issue" in { diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 0d34906886..cd03f99610 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -3048,6 +3048,23 @@ StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef Clauses, getCurFunction()->setHasBranchProtectedScope(); + // OpenMP [2.7.3, single Construct, Restrictions] + // The copyprivate clause must not be used with the nowait clause. + OMPClause *Nowait = nullptr; + OMPClause *Copyprivate = nullptr; + for (auto *Clause : Clauses) { + if (Clause->getClauseKind() == OMPC_nowait) + Nowait = Clause; + else if (Clause->getClauseKind() == OMPC_copyprivate) + Copyprivate = Clause; + if (Copyprivate && Nowait) { + Diag(Copyprivate->getLocStart(), + diag::err_omp_single_copyprivate_with_nowait); + Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); + return StmtError(); + } + } + return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); } diff --git a/test/OpenMP/single_ast_print.cpp b/test/OpenMP/single_ast_print.cpp index 65a007e271..b9eba9d7eb 100644 --- a/test/OpenMP/single_ast_print.cpp +++ b/test/OpenMP/single_ast_print.cpp @@ -14,10 +14,16 @@ T tmain(T argc) { static T a; // CHECK: static T a; #pragma omp parallel private(g) -#pragma omp single private(argc, b), firstprivate(c, d), nowait copyprivate(g) +#pragma omp single private(argc, b), firstprivate(c, d), nowait foo(); // CHECK-NEXT: #pragma omp parallel private(g) - // CHECK-NEXT: #pragma omp single private(argc,b) firstprivate(c,d) nowait copyprivate(g) + // CHECK-NEXT: #pragma omp single private(argc,b) firstprivate(c,d) nowait + // CHECK-NEXT: foo(); +#pragma omp parallel private(g) +#pragma omp single private(argc, b), firstprivate(c, d), copyprivate(g) + foo(); + // CHECK-NEXT: #pragma omp parallel private(g) + // CHECK-NEXT: #pragma omp single private(argc,b) firstprivate(c,d) copyprivate(g) // CHECK-NEXT: foo(); return T(); } @@ -27,10 +33,16 @@ int main(int argc, char **argv) { static int a; // CHECK: static int a; #pragma omp parallel private(g) -#pragma omp single private(argc, b), firstprivate(argv, c), nowait copyprivate(g) +#pragma omp single private(argc, b), firstprivate(argv, c), nowait + foo(); + // CHECK-NEXT: #pragma omp parallel private(g) + // CHECK-NEXT: #pragma omp single private(argc,b) firstprivate(argv,c) nowait + // CHECK-NEXT: foo(); +#pragma omp parallel private(g) +#pragma omp single private(argc, b), firstprivate(c, d), copyprivate(g) foo(); // CHECK-NEXT: #pragma omp parallel private(g) - // CHECK-NEXT: #pragma omp single private(argc,b) firstprivate(argv,c) nowait copyprivate(g) + // CHECK-NEXT: #pragma omp single private(argc,b) firstprivate(c,d) copyprivate(g) // CHECK-NEXT: foo(); return (tmain(argc) + tmain(argv[0][0])); } diff --git a/test/OpenMP/single_copyprivate_messages.cpp b/test/OpenMP/single_copyprivate_messages.cpp index 7bb145c6d3..252f2e6a4f 100644 --- a/test/OpenMP/single_copyprivate_messages.cpp +++ b/test/OpenMP/single_copyprivate_messages.cpp @@ -152,6 +152,8 @@ int main(int argc, char **argv) { #pragma omp parallel #pragma omp single firstprivate(i) copyprivate(i) // expected-error {{firstprivate variable cannot be copyprivate}} expected-note {{defined as firstprivate}} foo(); +#pragma omp single copyprivate(i) nowait // expected-error {{the 'copyprivate' clause must not be used with the 'nowait' clause}} expected-note {{'nowait' clause is here}} + foo(); return tmain(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain' requested here}} } -- 2.40.0