diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/StmtPrinter.cpp | 2 | ||||
-rw-r--r-- | clang/lib/AST/StmtProfile.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Basic/OpenMPKinds.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Parse/ParseOpenMP.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 65 | ||||
-rw-r--r-- | clang/lib/Sema/TreeTransform.h | 6 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderStmt.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriterStmt.cpp | 2 |
8 files changed, 64 insertions, 27 deletions
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 2a704c3a849..bf90a5e232a 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -667,6 +667,8 @@ void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) { void OMPClausePrinter::VisitOMPReadClause(OMPReadClause *) { OS << "read"; } +void OMPClausePrinter::VisitOMPWriteClause(OMPWriteClause *) { OS << "write"; } + template<typename T> void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { for (typename T::varlist_iterator I = Node->varlist_begin(), diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 4cf7077ee84..b65d07036b4 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -312,6 +312,8 @@ void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {} void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {} +void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {} + template<typename T> void OMPClauseProfiler::VisitOMPClauseList(T *Node) { for (auto *I : Node->varlists()) diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp index 78cfa18d8fe..db86cc713c3 100644 --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -109,6 +109,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, case OMPC_mergeable: case OMPC_flush: case OMPC_read: + case OMPC_write: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); @@ -169,6 +170,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, case OMPC_mergeable: case OMPC_flush: case OMPC_read: + case OMPC_write: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 9ba18b4e98a..a5bc4a44942 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -342,7 +342,7 @@ bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, /// | linear-clause | aligned-clause | collapse-clause | /// lastprivate-clause | reduction-clause | proc_bind-clause | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | -/// mergeable-clause | flush-clause | read-clause +/// mergeable-clause | flush-clause | read-clause | write-clause /// OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, bool FirstClause) { @@ -373,6 +373,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, if (!FirstClause) { Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind); + ErrorFound = true; } Clause = ParseOpenMPSingleExprClause(CKind); @@ -387,6 +388,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, if (!FirstClause) { Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind); + ErrorFound = true; } Clause = ParseOpenMPSimpleClause(CKind); @@ -397,6 +399,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, if (!FirstClause) { Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind); + ErrorFound = true; } Clause = ParseOpenMPSingleExprWithArgClause(CKind); @@ -406,6 +409,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, case OMPC_untied: case OMPC_mergeable: case OMPC_read: + case OMPC_write: // 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] @@ -413,6 +417,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, if (!FirstClause) { Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind); + ErrorFound = true; } Clause = ParseOpenMPClause(CKind); diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 7ec0d2b944a..318b00c5aa0 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -92,16 +92,15 @@ private: Scope *CurScope; SourceLocation ConstructLoc; bool OrderedRegion; - SourceLocation AtomicClauseLoc; SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, Scope *CurScope, SourceLocation Loc) : SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified), Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), - ConstructLoc(Loc), OrderedRegion(false), AtomicClauseLoc() {} + ConstructLoc(Loc), OrderedRegion(false) {} SharingMapTy() : SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified), Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), - ConstructLoc(), OrderedRegion(false), AtomicClauseLoc() {} + ConstructLoc(), OrderedRegion(false) {} }; typedef SmallVector<SharingMapTy, 64> StackTy; @@ -208,22 +207,6 @@ public: return false; } - /// \brief Checks if the 'atomic' construct has explicitly specified 'read', - /// 'update', 'write' or 'capture' clause. - bool hasAtomicClause() const { - return Stack.back().AtomicClauseLoc.isValid(); - } - /// \brief Gets location of explicitly specified clause for 'atomic' - /// construct. - SourceLocation getAtomicClauseLoc() const { - return Stack.back().AtomicClauseLoc; - } - /// \brief Sets location of explicitly specified clause for 'atomic' - /// directive. - void setAtomicClauseLoc(SourceLocation Loc) { - Stack.back().AtomicClauseLoc = Loc; - } - Scope *getCurScope() const { return Stack.back().CurScope; } Scope *getCurScope() { return Stack.back().CurScope; } SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } @@ -2403,15 +2386,34 @@ StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, // The point of exit cannot be a branch out of the structured block. // longjmp() and throw() must not violate the entry/exit criteria. // TODO further analysis of associated statements and clauses. + OpenMPClauseKind AtomicKind = OMPC_unknown; + SourceLocation AtomicKindLoc; for (auto *C : Clauses) { - if (C->getClauseKind() == OMPC_read) { - if (!isa<Expr>(CS->getCapturedStmt())) { - Diag(CS->getCapturedStmt()->getLocStart(), - diag::err_omp_atomic_read_not_expression_statement); - return StmtError(); + if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write) { + if (AtomicKind != OMPC_unknown) { + Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) + << SourceRange(C->getLocStart(), C->getLocEnd()); + Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) + << getOpenMPClauseName(AtomicKind); + } else { + AtomicKind = C->getClauseKind(); + AtomicKindLoc = C->getLocStart(); } } } + if (AtomicKind == OMPC_read) { + if (!isa<Expr>(CS->getCapturedStmt())) { + Diag(CS->getCapturedStmt()->getLocStart(), + diag::err_omp_atomic_read_not_expression_statement); + return StmtError(); + } + } else if (AtomicKind == OMPC_write) { + if (!isa<Expr>(CS->getCapturedStmt())) { + Diag(CS->getCapturedStmt()->getLocStart(), + diag::err_omp_atomic_write_not_expression_statement); + return StmtError(); + } + } getCurFunction()->setHasBranchProtectedScope(); @@ -2458,6 +2460,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, case OMPC_threadprivate: case OMPC_flush: case OMPC_read: + case OMPC_write: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -2500,7 +2503,6 @@ OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); } - ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, Expr *Op) { if (!Op) @@ -2662,6 +2664,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause( case OMPC_threadprivate: case OMPC_flush: case OMPC_read: + case OMPC_write: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -2778,6 +2781,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( case OMPC_threadprivate: case OMPC_flush: case OMPC_read: + case OMPC_write: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -2860,6 +2864,9 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, case OMPC_read: Res = ActOnOpenMPReadClause(StartLoc, EndLoc); break; + case OMPC_write: + Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); + break; case OMPC_if: case OMPC_final: case OMPC_num_threads: @@ -2908,10 +2915,14 @@ OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc) { - DSAStack->setAtomicClauseLoc(StartLoc); return new (Context) OMPReadClause(StartLoc, EndLoc); } +OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, + SourceLocation EndLoc) { + return new (Context) OMPWriteClause(StartLoc, EndLoc); +} + OMPClause *Sema::ActOnOpenMPVarListClause( OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, @@ -2966,6 +2977,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause( case OMPC_mergeable: case OMPC_threadprivate: case OMPC_read: + case OMPC_write: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -4266,3 +4278,4 @@ OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); } + diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index fff0e57ee74..66da412b2c1 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6768,6 +6768,12 @@ OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { } template <typename Derived> +OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { + // No need to rebuild this clause, no template-dependent parameters. + return C; +} + +template <typename Derived> OMPClause * TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { llvm::SmallVector<Expr *, 16> Vars; diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index ae870176d35..7cefa80e23f 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1718,6 +1718,9 @@ OMPClause *OMPClauseReader::readClause() { case OMPC_read: C = new (Context) OMPReadClause(); break; + case OMPC_write: + C = new (Context) OMPWriteClause(); + break; case OMPC_private: C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]); break; @@ -1814,6 +1817,8 @@ void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {} void OMPClauseReader::VisitOMPReadClause(OMPReadClause *) {} +void OMPClauseReader::VisitOMPWriteClause(OMPWriteClause *) {} + void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) { C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); unsigned NumVars = C->varlist_size(); diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index d42f9d65134..5048594bc65 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1737,6 +1737,8 @@ void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {} void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {} +void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {} + void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) { Record.push_back(C->varlist_size()); Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); |