From: Alexey Bataev Date: Thu, 24 Jul 2014 08:55:34 +0000 (+0000) Subject: [OPENMP] Initial parsing and sema analysis for clause 'seq_cst' of 'atomic' directive. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=22c2a0029346dbc3734976a5cca1188e68944e05;p=clang [OPENMP] Initial parsing and sema analysis for clause 'seq_cst' of 'atomic' directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213846 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 388d57e925..13a6dec759 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -2440,6 +2440,11 @@ bool RecursiveASTVisitor::VisitOMPCaptureClause(OMPCaptureClause *) { return true; } +template +bool RecursiveASTVisitor::VisitOMPSeqCstClause(OMPSeqCstClause *) { + return true; +} + template template bool RecursiveASTVisitor::VisitOMPClauseList(T *Node) { diff --git a/include/clang/AST/OpenMPClause.h b/include/clang/AST/OpenMPClause.h index c6c2022b4a..5f05b449de 100644 --- a/include/clang/AST/OpenMPClause.h +++ b/include/clang/AST/OpenMPClause.h @@ -887,6 +887,36 @@ public: StmtRange children() { return StmtRange(); } }; +/// \brief This represents 'seq_cst' clause in the '#pragma omp atomic' +/// directive. +/// +/// \code +/// #pragma omp atomic seq_cst +/// \endcode +/// In this example directive '#pragma omp atomic' has 'seq_cst' clause. +/// +class OMPSeqCstClause : public OMPClause { +public: + /// \brief Build 'seq_cst' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + /// + OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {} + + /// \brief Build an empty clause. + /// + OMPSeqCstClause() + : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {} + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == OMPC_seq_cst; + } + + StmtRange children() { return StmtRange(); } +}; + /// \brief This represents clause 'private' in the '#pragma omp ...' directives. /// /// \code diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 8de3101df5..ca66631c9b 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2462,6 +2462,11 @@ bool RecursiveASTVisitor::VisitOMPCaptureClause(OMPCaptureClause *) { return true; } +template +bool RecursiveASTVisitor::VisitOMPSeqCstClause(OMPSeqCstClause *) { + return true; +} + template template bool RecursiveASTVisitor::VisitOMPClauseList(T *Node) { diff --git a/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def index dd1621eae0..878bd9e4e6 100644 --- a/include/clang/Basic/OpenMPKinds.def +++ b/include/clang/Basic/OpenMPKinds.def @@ -105,6 +105,7 @@ OPENMP_CLAUSE(read, OMPReadClause) OPENMP_CLAUSE(write, OMPWriteClause) OPENMP_CLAUSE(update, OMPUpdateClause) OPENMP_CLAUSE(capture, OMPCaptureClause) +OPENMP_CLAUSE(seq_cst, OMPSeqCstClause) // Clauses allowed for OpenMP directive 'parallel'. OPENMP_PARALLEL_CLAUSE(if) @@ -202,11 +203,12 @@ OPENMP_TASK_CLAUSE(shared) OPENMP_TASK_CLAUSE(untied) OPENMP_TASK_CLAUSE(mergeable) -// TODO More clauses allowed for OpenMP directive 'atomic'. +// Clauses allowed for OpenMP directive 'atomic'. OPENMP_ATOMIC_CLAUSE(read) OPENMP_ATOMIC_CLAUSE(write) OPENMP_ATOMIC_CLAUSE(update) OPENMP_ATOMIC_CLAUSE(capture) +OPENMP_ATOMIC_CLAUSE(seq_cst) #undef OPENMP_SCHEDULE_KIND #undef OPENMP_PROC_BIND_KIND diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 1fb42d1670..d4181b7edd 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -7494,6 +7494,9 @@ public: /// \brief Called on well-formed 'capture' clause. OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc); + /// \brief Called on well-formed 'seq_cst' clause. + OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc, + SourceLocation EndLoc); OMPClause * ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef Vars, diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 887f201742..1d1b2bca79 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -677,6 +677,10 @@ void OMPClausePrinter::VisitOMPCaptureClause(OMPCaptureClause *) { OS << "capture"; } +void OMPClausePrinter::VisitOMPSeqCstClause(OMPSeqCstClause *) { + OS << "seq_cst"; +} + template void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { for (typename T::varlist_iterator I = Node->varlist_begin(), diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 6d6e319bd3..76c7843481 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -318,6 +318,8 @@ void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {} void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {} +void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {} + template void OMPClauseProfiler::VisitOMPClauseList(T *Node) { for (auto *I : Node->varlists()) diff --git a/lib/Basic/OpenMPKinds.cpp b/lib/Basic/OpenMPKinds.cpp index b125586ed1..7b277b477d 100644 --- a/lib/Basic/OpenMPKinds.cpp +++ b/lib/Basic/OpenMPKinds.cpp @@ -112,6 +112,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, case OMPC_write: case OMPC_update: case OMPC_capture: + case OMPC_seq_cst: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); @@ -175,6 +176,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, case OMPC_write: case OMPC_update: case OMPC_capture: + case OMPC_seq_cst: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index 6c8fd640f9..4044b112c8 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -343,7 +343,7 @@ bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, /// lastprivate-clause | reduction-clause | proc_bind-clause | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | /// mergeable-clause | flush-clause | read-clause | write-clause | -/// update-clause | capture-clause +/// update-clause | capture-clause | seq_cst-clause /// OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, bool FirstClause) { @@ -413,6 +413,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, case OMPC_write: case OMPC_update: case OMPC_capture: + case OMPC_seq_cst: // OpenMP [2.7.1, Restrictions, p. 9] // Only one ordered clause can appear on a loop directive. // OpenMP [2.7.1, Restrictions, C/C++, p. 4] diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 5bbed68011..046ef55254 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -2485,6 +2485,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, case OMPC_write: case OMPC_update: case OMPC_capture: + case OMPC_seq_cst: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -2691,6 +2692,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause( case OMPC_write: case OMPC_update: case OMPC_capture: + case OMPC_seq_cst: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -2810,6 +2812,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( case OMPC_write: case OMPC_update: case OMPC_capture: + case OMPC_seq_cst: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -2901,6 +2904,9 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, case OMPC_capture: Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); break; + case OMPC_seq_cst: + Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); + break; case OMPC_if: case OMPC_final: case OMPC_num_threads: @@ -2967,6 +2973,11 @@ OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, return new (Context) OMPCaptureClause(StartLoc, EndLoc); } +OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, + SourceLocation EndLoc) { + return new (Context) OMPSeqCstClause(StartLoc, EndLoc); +} + OMPClause *Sema::ActOnOpenMPVarListClause( OpenMPClauseKind Kind, ArrayRef VarList, Expr *TailExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, @@ -3024,6 +3035,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause( case OMPC_write: case OMPC_update: case OMPC_capture: + case OMPC_seq_cst: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 95b027a71c..a098b537be 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -6787,6 +6787,13 @@ TreeTransform::TransformOMPCaptureClause(OMPCaptureClause *C) { return C; } +template +OMPClause * +TreeTransform::TransformOMPSeqCstClause(OMPSeqCstClause *C) { + // No need to rebuild this clause, no template-dependent parameters. + return C; +} + template OMPClause * TreeTransform::TransformOMPPrivateClause(OMPPrivateClause *C) { diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 90987fe7ae..c4e88f0f18 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -1727,6 +1727,9 @@ OMPClause *OMPClauseReader::readClause() { case OMPC_capture: C = new (Context) OMPCaptureClause(); break; + case OMPC_seq_cst: + C = new (Context) OMPSeqCstClause(); + break; case OMPC_private: C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]); break; @@ -1829,6 +1832,8 @@ void OMPClauseReader::VisitOMPUpdateClause(OMPUpdateClause *) {} void OMPClauseReader::VisitOMPCaptureClause(OMPCaptureClause *) {} +void OMPClauseReader::VisitOMPSeqCstClause(OMPSeqCstClause *) {} + void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) { C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); unsigned NumVars = C->varlist_size(); diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 0ce5dfde83..cee94c401c 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -1743,6 +1743,8 @@ void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *) {} void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {} +void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {} + void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) { Record.push_back(C->varlist_size()); Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); diff --git a/test/OpenMP/atomic_ast_print.cpp b/test/OpenMP/atomic_ast_print.cpp index 31c0892013..e75d291eab 100644 --- a/test/OpenMP/atomic_ast_print.cpp +++ b/test/OpenMP/atomic_ast_print.cpp @@ -25,6 +25,21 @@ T foo(T argc) { a = b; b++; } +#pragma omp atomic seq_cst + a++; +#pragma omp atomic read seq_cst + a = argc; +#pragma omp atomic seq_cst write + a = argc + argc; +#pragma omp atomic update seq_cst + a = a + argc; +#pragma omp atomic seq_cst capture + a = b++; +#pragma omp atomic capture seq_cst + { + a = b; + b++; + } return T(); } @@ -44,6 +59,21 @@ T foo(T argc) { // CHECK-NEXT: a = b; // CHECK-NEXT: b++; // CHECK-NEXT: } +// CHECK-NEXT: #pragma omp atomic seq_cst +// CHECK-NEXT: a++; +// CHECK-NEXT: #pragma omp atomic read seq_cst +// CHECK-NEXT: a = argc; +// CHECK-NEXT: #pragma omp atomic seq_cst write +// CHECK-NEXT: a = argc + argc; +// CHECK-NEXT: #pragma omp atomic update seq_cst +// CHECK-NEXT: a = a + argc; +// CHECK-NEXT: #pragma omp atomic seq_cst capture +// CHECK-NEXT: a = b++; +// CHECK-NEXT: #pragma omp atomic capture seq_cst +// CHECK-NEXT: { +// CHECK-NEXT: a = b; +// CHECK-NEXT: b++; +// CHECK-NEXT: } // CHECK: T a = T(); // CHECK-NEXT: #pragma omp atomic // CHECK-NEXT: a++; @@ -60,6 +90,21 @@ T foo(T argc) { // CHECK-NEXT: a = b; // CHECK-NEXT: b++; // CHECK-NEXT: } +// CHECK-NEXT: #pragma omp atomic seq_cst +// CHECK-NEXT: a++; +// CHECK-NEXT: #pragma omp atomic read seq_cst +// CHECK-NEXT: a = argc; +// CHECK-NEXT: #pragma omp atomic seq_cst write +// CHECK-NEXT: a = argc + argc; +// CHECK-NEXT: #pragma omp atomic update seq_cst +// CHECK-NEXT: a = a + argc; +// CHECK-NEXT: #pragma omp atomic seq_cst capture +// CHECK-NEXT: a = b++; +// CHECK-NEXT: #pragma omp atomic capture seq_cst +// CHECK-NEXT: { +// CHECK-NEXT: a = b; +// CHECK-NEXT: b++; +// CHECK-NEXT: } int main(int argc, char **argv) { int b = 0; @@ -80,6 +125,21 @@ int main(int argc, char **argv) { a = b; b++; } +#pragma omp atomic seq_cst + a++; +#pragma omp atomic read seq_cst + a = argc; +#pragma omp atomic seq_cst write + a = argc + argc; +#pragma omp atomic update seq_cst + a = a + argc; +#pragma omp atomic seq_cst capture + a = b++; +#pragma omp atomic capture seq_cst + { + a = b; + b++; + } // CHECK-NEXT: #pragma omp atomic // CHECK-NEXT: a++; // CHECK-NEXT: #pragma omp atomic read @@ -95,6 +155,21 @@ int main(int argc, char **argv) { // CHECK-NEXT: a = b; // CHECK-NEXT: b++; // CHECK-NEXT: } + // CHECK-NEXT: #pragma omp atomic seq_cst + // CHECK-NEXT: a++; + // CHECK-NEXT: #pragma omp atomic read seq_cst + // CHECK-NEXT: a = argc; + // CHECK-NEXT: #pragma omp atomic seq_cst write + // CHECK-NEXT: a = argc + argc; + // CHECK-NEXT: #pragma omp atomic update seq_cst + // CHECK-NEXT: a = a + argc; + // CHECK-NEXT: #pragma omp atomic seq_cst capture + // CHECK-NEXT: a = b++; + // CHECK-NEXT: #pragma omp atomic capture seq_cst + // CHECK-NEXT: { + // CHECK-NEXT: a = b; + // CHECK-NEXT: b++; + // CHECK-NEXT: } return foo(a); } diff --git a/test/OpenMP/atomic_messages.cpp b/test/OpenMP/atomic_messages.cpp index 66f7c9db64..b53133f352 100644 --- a/test/OpenMP/atomic_messages.cpp +++ b/test/OpenMP/atomic_messages.cpp @@ -143,6 +143,41 @@ int capture() { return capture(); } +template +T seq_cst() { + T a, b = 0; +// Test for atomic seq_cst +#pragma omp atomic seq_cst + // expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}} + ; +// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'seq_cst' clause}} +#pragma omp atomic seq_cst seq_cst + a += b; + +#pragma omp atomic update seq_cst + // expected-error@+1 {{the statement for 'atomic update' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}} + ; + + return T(); +} + +int seq_cst() { + int a, b = 0; +// Test for atomic seq_cst +#pragma omp atomic seq_cst + // expected-error@+1 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}} + ; +// expected-error@+1 {{directive '#pragma omp atomic' cannot contain more than one 'seq_cst' clause}} +#pragma omp atomic seq_cst seq_cst + a += b; + +#pragma omp atomic update seq_cst + // expected-error@+1 {{the statement for 'atomic update' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}} + ; + + return seq_cst(); +} + template T mixed() { T a, b = T(); diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index e5a438bd30..57bea9927d 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1989,6 +1989,8 @@ void OMPClauseEnqueue::VisitOMPUpdateClause(const OMPUpdateClause *) {} void OMPClauseEnqueue::VisitOMPCaptureClause(const OMPCaptureClause *) {} +void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {} + template void OMPClauseEnqueue::VisitOMPClauseList(T *Node) { for (const auto *I : Node->varlists())