From: Alexey Bataev Date: Tue, 7 Oct 2014 10:13:33 +0000 (+0000) Subject: [OPENMP] 'omp teams' directive basic support. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=95a2fbb94657bd83240024f9f86ce927d81c7cff;p=clang [OPENMP] 'omp teams' directive basic support. Includes parsing and semantic analysis for 'omp teams' directive support from OpenMP 4.0. Adds additional analysis to 'omp target' directive with 'omp teams' directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219197 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 1175196436..911f7cc966 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -2221,7 +2221,11 @@ enum CXCursorKind { */ CXCursor_OMPTargetDirective = 252, - CXCursor_LastStmt = CXCursor_OMPTargetDirective, + /** \brief OpenMP teams directive. + */ + CXCursor_OMPTeamsDirective = 253, + + CXCursor_LastStmt = CXCursor_OMPTeamsDirective, /** * \brief Cursor that represents the translation unit itself. diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 0d470891fa..078451cf54 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -2350,6 +2350,9 @@ DEF_TRAVERSE_STMT(OMPAtomicDirective, DEF_TRAVERSE_STMT(OMPTargetDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) +DEF_TRAVERSE_STMT(OMPTeamsDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) + // OpenMP clauses. template bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 821eacb21f..cf8131dc36 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2372,6 +2372,9 @@ DEF_TRAVERSE_STMT(OMPAtomicDirective, DEF_TRAVERSE_STMT(OMPTargetDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) +DEF_TRAVERSE_STMT(OMPTeamsDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) + // OpenMP clauses. template bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { diff --git a/include/clang/AST/StmtOpenMP.h b/include/clang/AST/StmtOpenMP.h index 249ee44553..6a6abb9b99 100644 --- a/include/clang/AST/StmtOpenMP.h +++ b/include/clang/AST/StmtOpenMP.h @@ -1527,6 +1527,64 @@ public: } }; +/// \brief This represents '#pragma omp teams' directive. +/// +/// \code +/// #pragma omp teams if(a) +/// \endcode +/// In this example directive '#pragma omp teams' has clause 'if' with +/// condition 'a'. +/// +class OMPTeamsDirective : public OMPExecutableDirective { + friend class ASTStmtReader; + /// \brief Build directive with the given start and end location. + /// + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending location of the directive. + /// \param NumClauses Number of clauses. + /// + OMPTeamsDirective(SourceLocation StartLoc, SourceLocation EndLoc, + unsigned NumClauses) + : OMPExecutableDirective(this, OMPTeamsDirectiveClass, OMPD_teams, + StartLoc, EndLoc, NumClauses, 1) {} + + /// \brief Build an empty directive. + /// + /// \param NumClauses Number of clauses. + /// + explicit OMPTeamsDirective(unsigned NumClauses) + : OMPExecutableDirective(this, OMPTeamsDirectiveClass, OMPD_teams, + SourceLocation(), SourceLocation(), NumClauses, + 1) {} + +public: + /// \brief Creates directive with a list of \a Clauses. + /// + /// \param C AST context. + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending Location of the directive. + /// \param Clauses List of clauses. + /// \param AssociatedStmt Statement, associated with the directive. + /// + static OMPTeamsDirective *Create(const ASTContext &C, SourceLocation StartLoc, + SourceLocation EndLoc, + ArrayRef Clauses, + Stmt *AssociatedStmt); + + /// \brief Creates an empty directive with the place for \a NumClauses + /// clauses. + /// + /// \param C AST context. + /// \param NumClauses Number of clauses. + /// + static OMPTeamsDirective *CreateEmpty(const ASTContext &C, + unsigned NumClauses, EmptyShell); + + static bool classof(const Stmt *T) { + return T->getStmtClass() == OMPTeamsDirectiveClass; + } +}; + } // end namespace clang #endif diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index cb81078880..1957db33dc 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -7262,7 +7262,8 @@ def err_omp_reduction_id_not_compatible : Error< def err_omp_prohibited_region : Error< "region cannot be%select{| closely}0 nested inside '%1' region" "%select{|; perhaps you forget to enclose 'omp %3' directive into a parallel region?|" - "; perhaps you forget to enclose 'omp %3' directive into a for or a parallel for region with 'ordered' clause?}2">; + "; perhaps you forget to enclose 'omp %3' directive into a for or a parallel for region with 'ordered' clause?|" + "; perhaps you forget to enclose 'omp %3' directive into a target region?}2">; def err_omp_prohibited_region_simd : Error< "OpenMP constructs may not be nested inside a simd region">; def err_omp_prohibited_region_atomic : Error< @@ -7305,6 +7306,12 @@ def err_omp_atomic_several_clauses : Error< "directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update' or 'capture' clause">; def note_omp_atomic_previous_clause : Note< "'%0' clause used here">; +def err_omp_target_contains_not_only_teams : Error< + "target construct with nested teams region contains statements outside of the teams construct">; +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">; } // end of OpenMP category let CategoryName = "Related Result Type Issue" in { diff --git a/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def index d238120d6d..0145db0593 100644 --- a/include/clang/Basic/OpenMPKinds.def +++ b/include/clang/Basic/OpenMPKinds.def @@ -57,6 +57,9 @@ #ifndef OPENMP_TARGET_CLAUSE # define OPENMP_TARGET_CLAUSE(Name) #endif +#ifndef OPENMP_TEAMS_CLAUSE +# define OPENMP_TEAMS_CLAUSE(Name) +#endif #ifndef OPENMP_DEFAULT_KIND # define OPENMP_DEFAULT_KIND(Name) #endif @@ -85,6 +88,7 @@ OPENMP_DIRECTIVE(flush) OPENMP_DIRECTIVE(ordered) OPENMP_DIRECTIVE(atomic) OPENMP_DIRECTIVE(target) +OPENMP_DIRECTIVE(teams) OPENMP_DIRECTIVE_EXT(parallel_for, "parallel for") OPENMP_DIRECTIVE_EXT(parallel_for_simd, "parallel for simd") OPENMP_DIRECTIVE_EXT(parallel_sections, "parallel sections") @@ -255,6 +259,14 @@ OPENMP_ATOMIC_CLAUSE(seq_cst) // TODO More clauses for 'target' directive. OPENMP_TARGET_CLAUSE(if) +// Clauses allowed for OpenMP directive 'teams'. +// TODO More clauses for 'teams' directive. +OPENMP_TEAMS_CLAUSE(default) +OPENMP_TEAMS_CLAUSE(private) +OPENMP_TEAMS_CLAUSE(firstprivate) +OPENMP_TEAMS_CLAUSE(shared) +OPENMP_TEAMS_CLAUSE(reduction) + #undef OPENMP_SCHEDULE_KIND #undef OPENMP_PROC_BIND_KIND #undef OPENMP_DEFAULT_KIND @@ -270,6 +282,7 @@ OPENMP_TARGET_CLAUSE(if) #undef OPENMP_TASK_CLAUSE #undef OPENMP_ATOMIC_CLAUSE #undef OPENMP_TARGET_CLAUSE +#undef OPENMP_TEAMS_CLAUSE #undef OPENMP_SIMD_CLAUSE #undef OPENMP_FOR_CLAUSE #undef OPENMP_FOR_SIMD_CLAUSE diff --git a/include/clang/Basic/OpenMPKinds.h b/include/clang/Basic/OpenMPKinds.h index 526cbb26cf..e2f115113e 100644 --- a/include/clang/Basic/OpenMPKinds.h +++ b/include/clang/Basic/OpenMPKinds.h @@ -93,6 +93,12 @@ bool isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind); /// parallel', otherwise - false. bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind); +/// \brief Checks if the specified directive is a teams-kind directive. +/// \param DKind Specified directive. +/// \return true - the directive is a teams-like directive like 'omp teams', +/// otherwise - false. +bool isOpenMPTeamsDirective(OpenMPDirectiveKind DKind); + /// \brief Checks if the specified directive is a simd directive. /// \param DKind Specified directive. /// \return true - the directive is a simd directive like 'omp simd', diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td index c1dc4d2cf9..be025e344a 100644 --- a/include/clang/Basic/StmtNodes.td +++ b/include/clang/Basic/StmtNodes.td @@ -199,3 +199,4 @@ def OMPFlushDirective : DStmt; def OMPOrderedDirective : DStmt; def OMPAtomicDirective : DStmt; def OMPTargetDirective : DStmt; +def OMPTeamsDirective : DStmt; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index ddc997d64d..3f52f2dccb 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -7501,12 +7501,16 @@ public: StmtResult ActOnOpenMPAtomicDirective(ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); - /// \brief Called on well-formed '\#pragma omp target' after parsing of the /// associated statement. StmtResult ActOnOpenMPTargetDirective(ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); + /// \brief Called on well-formed '\#pragma omp teams' after parsing of the + /// associated statement. + StmtResult ActOnOpenMPTeamsDirective(ArrayRef Clauses, + Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc); OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 49f2b1b7fa..d635102af4 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -1360,6 +1360,7 @@ namespace clang { STMT_OMP_ORDERED_DIRECTIVE, STMT_OMP_ATOMIC_DIRECTIVE, STMT_OMP_TARGET_DIRECTIVE, + STMT_OMP_TEAMS_DIRECTIVE, // ARC EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index af19af4943..c645d4aa34 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -1942,3 +1942,29 @@ OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C, return new (Mem) OMPTargetDirective(NumClauses); } +OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C, + SourceLocation StartLoc, + SourceLocation EndLoc, + ArrayRef Clauses, + Stmt *AssociatedStmt) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), + llvm::alignOf()); + void *Mem = + C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); + OMPTeamsDirective *Dir = + new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size()); + Dir->setClauses(Clauses); + Dir->setAssociatedStmt(AssociatedStmt); + return Dir; +} + +OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C, + unsigned NumClauses, + EmptyShell) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), + llvm::alignOf()); + void *Mem = + C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); + return new (Mem) OMPTeamsDirective(NumClauses); +} + diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 4ed996254b..301d6a7bb6 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -928,6 +928,11 @@ void StmtPrinter::VisitOMPTargetDirective(OMPTargetDirective *Node) { PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPTeamsDirective(OMPTeamsDirective *Node) { + Indent() << "#pragma omp teams "; + PrintOMPExecutableDirective(Node); +} + //===----------------------------------------------------------------------===// // Expr printing methods. //===----------------------------------------------------------------------===// diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 9bcb5929ed..2da2174bf6 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -466,6 +466,10 @@ void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) { VisitOMPExecutableDirective(S); } +void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) { + VisitOMPExecutableDirective(S); +} + void StmtProfiler::VisitExpr(const Expr *S) { VisitStmt(S); } diff --git a/lib/Basic/OpenMPKinds.cpp b/lib/Basic/OpenMPKinds.cpp index d4e07e876c..5b4ef28297 100644 --- a/lib/Basic/OpenMPKinds.cpp +++ b/lib/Basic/OpenMPKinds.cpp @@ -309,6 +309,16 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, #define OPENMP_TARGET_CLAUSE(Name) \ case OMPC_##Name: \ return true; +#include "clang/Basic/OpenMPKinds.def" + default: + break; + } + break; + case OMPD_teams: + switch (CKind) { +#define OPENMP_TEAMS_CLAUSE(Name) \ + case OMPC_##Name: \ + return true; #include "clang/Basic/OpenMPKinds.def" default: break; @@ -348,6 +358,10 @@ bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) { DKind == OMPD_parallel_sections; // TODO add next directives. } +bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) { + return DKind == OMPD_teams; // TODO add next directives. +} + bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) { return DKind == OMPD_simd || DKind == OMPD_for_simd || DKind == OMPD_parallel_for_simd; // TODO add next directives. diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 81031f14ae..b970e4f1ab 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -236,6 +236,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::OMPTargetDirectiveClass: EmitOMPTargetDirective(cast(*S)); break; + case Stmt::OMPTeamsDirectiveClass: + EmitOMPTeamsDirective(cast(*S)); + break; } } diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index 985cc0e62a..c2864689be 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -345,3 +345,7 @@ void CodeGenFunction::EmitOMPTargetDirective(const OMPTargetDirective &) { llvm_unreachable("CodeGen for 'omp target' is not supported yet."); } +void CodeGenFunction::EmitOMPTeamsDirective(const OMPTeamsDirective &) { + llvm_unreachable("CodeGen for 'omp teams' is not supported yet."); +} + diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index d07ad5d348..8f9d930e4f 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -2014,6 +2014,7 @@ public: void EmitOMPOrderedDirective(const OMPOrderedDirective &S); void EmitOMPAtomicDirective(const OMPAtomicDirective &S); void EmitOMPTargetDirective(const OMPTargetDirective &S); + void EmitOMPTeamsDirective(const OMPTeamsDirective &S); /// Helpers for 'omp simd' directive. void EmitOMPLoopBody(const OMPLoopDirective &Directive, diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index 1682c83bab..3a119a601e 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -108,6 +108,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { case OMPD_parallel_sections: case OMPD_atomic: case OMPD_target: + case OMPD_teams: Diag(Tok, diag::err_omp_unexpected_directive) << getOpenMPDirectiveName(DKind); break; @@ -127,7 +128,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { /// 'section' | 'single' | 'master' | 'critical' [ '(' ')' ] | /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | /// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' | -/// 'for simd' | 'parallel for simd' | 'target' {clause} +/// 'for simd' | 'parallel for simd' | 'target' | 'teams' {clause} /// annot_pragma_openmp_end /// StmtResult @@ -196,7 +197,8 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) { case OMPD_task: case OMPD_ordered: case OMPD_atomic: - case OMPD_target: { + case OMPD_target: + case OMPD_teams: { ConsumeToken(); // Parse directive name of the 'critical' directive if any. if (DKind == OMPD_critical) { diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index ff2b282609..c4a813d45c 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -92,15 +92,16 @@ private: Scope *CurScope; SourceLocation ConstructLoc; bool OrderedRegion; + SourceLocation InnerTeamsRegionLoc; 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) {} + ConstructLoc(Loc), OrderedRegion(false), InnerTeamsRegionLoc() {} SharingMapTy() : SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified), Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), - ConstructLoc(), OrderedRegion(false) {} + ConstructLoc(), OrderedRegion(false), InnerTeamsRegionLoc() {} }; typedef SmallVector StackTy; @@ -207,13 +208,30 @@ public: return false; } + /// \brief Marks current target region as one with closely nested teams + /// region. + void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { + if (Stack.size() > 2) + Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; + } + /// \brief Returns true, if current region has closely nested teams region. + bool hasInnerTeamsRegion() const { + return getInnerTeamsRegionLoc().isValid(); + } + /// \brief Returns location of the nested teams region (if any). + SourceLocation getInnerTeamsRegionLoc() const { + if (Stack.size() > 1) + return Stack.back().InnerTeamsRegionLoc; + return SourceLocation(); + } + Scope *getCurScope() const { return Stack.back().CurScope; } Scope *getCurScope() { return Stack.back().CurScope; } SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } }; bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || - DKind == OMPD_unknown; + isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; } } // namespace @@ -276,7 +294,8 @@ DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, // In a parallel construct, if no default clause is present, these // variables are shared. DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; - if (isOpenMPParallelDirective(DVar.DKind)) { + if (isOpenMPParallelDirective(DVar.DKind) || + isOpenMPTeamsDirective(DVar.DKind)) { DVar.CKind = OMPC_shared; return DVar; } @@ -933,7 +952,8 @@ public: DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), [](OpenMPDirectiveKind K) -> bool { return isOpenMPParallelDirective(K) || - isOpenMPWorksharingDirective(K); + isOpenMPWorksharingDirective(K) || + isOpenMPTeamsDirective(K); }, false); if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { @@ -1152,6 +1172,18 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { Params); break; } + case OMPD_teams: { + QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); + QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); + Sema::CapturedParamNameType Params[] = { + std::make_pair(".global_tid.", KmpInt32PtrTy), + std::make_pair(".bound_tid.", KmpInt32PtrTy), + std::make_pair(StringRef(), QualType()) // __context with shared vars + }; + ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, + Params); + break; + } case OMPD_threadprivate: llvm_unreachable("OpenMP Directive is not allowed"); case OMPD_unknown: @@ -1187,6 +1219,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel | ordered | + | // | parallel | atomic | * | // | parallel | target | * | + // | parallel | teams | + | // +------------------+-----------------+------------------------------------+ // | for | parallel | * | // | for | for | + | @@ -1208,6 +1241,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for | ordered | * (if construct is ordered) | // | for | atomic | * | // | for | target | * | + // | for | teams | + | // +------------------+-----------------+------------------------------------+ // | master | parallel | * | // | master | for | + | @@ -1229,6 +1263,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | master | ordered | + | // | master | atomic | * | // | master | target | * | + // | master | teams | + | // +------------------+-----------------+------------------------------------+ // | critical | parallel | * | // | critical | for | + | @@ -1249,6 +1284,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | critical | ordered | + | // | critical | atomic | * | // | critical | target | * | + // | critical | teams | + | // +------------------+-----------------+------------------------------------+ // | simd | parallel | | // | simd | for | | @@ -1270,6 +1306,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | simd | ordered | | // | simd | atomic | | // | simd | target | | + // | simd | teams | | // +------------------+-----------------+------------------------------------+ // | for simd | parallel | | // | for simd | for | | @@ -1291,6 +1328,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for simd | ordered | | // | for simd | atomic | | // | for simd | target | | + // | for simd | teams | | // +------------------+-----------------+------------------------------------+ // | parallel for simd| parallel | | // | parallel for simd| for | | @@ -1312,6 +1350,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for simd| ordered | | // | parallel for simd| atomic | | // | parallel for simd| target | | + // | parallel for simd| teams | | // +------------------+-----------------+------------------------------------+ // | sections | parallel | * | // | sections | for | + | @@ -1333,6 +1372,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | sections | ordered | + | // | sections | atomic | * | // | sections | target | * | + // | sections | teams | + | // +------------------+-----------------+------------------------------------+ // | section | parallel | * | // | section | for | + | @@ -1354,6 +1394,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | section | ordered | + | // | section | atomic | * | // | section | target | * | + // | section | teams | + | // +------------------+-----------------+------------------------------------+ // | single | parallel | * | // | single | for | + | @@ -1375,6 +1416,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | single | ordered | + | // | single | atomic | * | // | single | target | * | + // | single | teams | + | // +------------------+-----------------+------------------------------------+ // | parallel for | parallel | * | // | parallel for | for | + | @@ -1396,6 +1438,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for | ordered | * (if construct is ordered) | // | parallel for | atomic | * | // | parallel for | target | * | + // | parallel for | teams | + | // +------------------+-----------------+------------------------------------+ // | parallel sections| parallel | * | // | parallel sections| for | + | @@ -1417,6 +1460,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel sections| ordered | + | // | parallel sections| atomic | * | // | parallel sections| target | * | + // | parallel sections| teams | + | // +------------------+-----------------+------------------------------------+ // | task | parallel | * | // | task | for | + | @@ -1438,6 +1482,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | task | ordered | + | // | task | atomic | * | // | task | target | * | + // | task | teams | + | // +------------------+-----------------+------------------------------------+ // | ordered | parallel | * | // | ordered | for | + | @@ -1459,6 +1504,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | ordered | ordered | + | // | ordered | atomic | * | // | ordered | target | * | + // | ordered | teams | + | // +------------------+-----------------+------------------------------------+ // | atomic | parallel | | // | atomic | for | | @@ -1480,6 +1526,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | atomic | ordered | | // | atomic | atomic | | // | atomic | target | | + // | atomic | teams | | // +------------------+-----------------+------------------------------------+ // | target | parallel | * | // | target | for | * | @@ -1501,6 +1548,29 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | target | ordered | * | // | target | atomic | * | // | target | target | * | + // | target | teams | * | + // +------------------+-----------------+------------------------------------+ + // | teams | parallel | * | + // | teams | for | + | + // | teams | for simd | + | + // | teams | master | + | + // | teams | critical | + | + // | teams | simd | + | + // | teams | sections | + | + // | teams | section | + | + // | teams | single | + | + // | teams | parallel for | * | + // | teams |parallel for simd| * | + // | teams |parallel sections| * | + // | teams | task | + | + // | teams | taskyield | + | + // | teams | barrier | + | + // | teams | taskwait | + | + // | teams | flush | + | + // | teams | ordered | + | + // | teams | atomic | + | + // | teams | target | + | + // | teams | teams | + | // +------------------+-----------------+------------------------------------+ if (Stack->getCurScope()) { auto ParentRegion = Stack->getParentDirective(); @@ -1509,7 +1579,8 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, enum { NoRecommend, ShouldBeInParallelRegion, - ShouldBeInOrderedRegion + ShouldBeInOrderedRegion, + ShouldBeInTargetRegion } Recommend = NoRecommend; if (isOpenMPSimdDirective(ParentRegion)) { // OpenMP [2.16, Nesting of Regions] @@ -1604,6 +1675,22 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, ParentRegion == OMPD_task || !Stack->isParentOrderedRegion(); Recommend = ShouldBeInOrderedRegion; + } else if (isOpenMPTeamsDirective(CurrentRegion)) { + // OpenMP [2.16, Nesting of Regions] + // If specified, a teams construct must be contained within a target + // construct. + NestingProhibited = ParentRegion != OMPD_target; + Recommend = ShouldBeInTargetRegion; + Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); + } + if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { + // OpenMP [2.16, Nesting of Regions] + // distribute, parallel, parallel sections, parallel workshare, and the + // parallel loop and parallel loop SIMD constructs are the only OpenMP + // constructs that can be closely nested in the teams region. + // TODO: add distribute directive. + NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); + Recommend = ShouldBeInParallelRegion; } if (NestingProhibited) { SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) @@ -1743,6 +1830,10 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); break; + case OMPD_teams: + Res = + ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); + break; case OMPD_target: Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); @@ -3161,11 +3252,58 @@ StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef Clauses, SourceLocation EndLoc) { assert(AStmt && isa(AStmt) && "Captured statement expected"); + // OpenMP [2.16, Nesting of Regions] + // If specified, a teams construct must be contained within a target + // construct. That target construct must contain no statements or directives + // outside of the teams construct. + if (DSAStack->hasInnerTeamsRegion()) { + auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); + bool OMPTeamsFound = true; + if (auto *CS = dyn_cast(S)) { + auto I = CS->body_begin(); + while (I != CS->body_end()) { + auto OED = dyn_cast(*I); + if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { + OMPTeamsFound = false; + break; + } + ++I; + } + assert(I != CS->body_end() && "Not found statement"); + S = *I; + } + if (!OMPTeamsFound) { + Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); + Diag(DSAStack->getInnerTeamsRegionLoc(), + diag::note_omp_nested_teams_construct_here); + Diag(S->getLocStart(), diag::note_omp_nested_statement_here) + << isa(S); + return StmtError(); + } + } + getCurFunction()->setHasBranchProtectedScope(); return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); } +StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef Clauses, + Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc) { + assert(AStmt && isa(AStmt) && "Captured statement expected"); + CapturedStmt *CS = cast(AStmt); + // 1.2.2 OpenMP Language Terminology + // Structured block - An executable statement with a single entry at the + // top and a single exit at the bottom. + // The point of exit cannot be a branch out of the structured block. + // longjmp() and throw() must not violate the entry/exit criteria. + CS->getCapturedDecl()->setNothrow(); + + getCurFunction()->setHasBranchProtectedScope(); + + return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); +} + OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, SourceLocation StartLoc, SourceLocation LParenLoc, diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 687f16473d..08a134a30b 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -6693,6 +6693,17 @@ TreeTransform::TransformOMPTargetDirective(OMPTargetDirective *D) { return Res; } +template +StmtResult +TreeTransform::TransformOMPTeamsDirective(OMPTeamsDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, + D->getLocStart()); + StmtResult Res = getDerived().TransformOMPExecutableDirective(D); + getDerived().getSema().EndOpenMPDSABlock(Res.get()); + return Res; +} + //===----------------------------------------------------------------------===// // OpenMP clause transformation //===----------------------------------------------------------------------===// diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index c8343373ad..e5b1c96619 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -2107,6 +2107,13 @@ void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) { VisitOMPExecutableDirective(D); } +void ASTStmtReader::VisitOMPTeamsDirective(OMPTeamsDirective *D) { + VisitStmt(D); + // The NumClauses field was read in ReadStmtFromStream. + ++Idx; + VisitOMPExecutableDirective(D); +} + //===----------------------------------------------------------------------===// // ASTReader Implementation //===----------------------------------------------------------------------===// @@ -2692,6 +2699,11 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { Context, Record[ASTStmtReader::NumStmtFields], Empty); break; + case STMT_OMP_TEAMS_DIRECTIVE: + S = OMPTeamsDirective::CreateEmpty( + Context, Record[ASTStmtReader::NumStmtFields], Empty); + break; + case EXPR_CXX_OPERATOR_CALL: S = new (Context) CXXOperatorCallExpr(Context, Empty); break; diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 80d42b8ae5..775c1bb6d0 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -1992,6 +1992,13 @@ void ASTStmtWriter::VisitOMPOrderedDirective(OMPOrderedDirective *D) { Code = serialization::STMT_OMP_ORDERED_DIRECTIVE; } +void ASTStmtWriter::VisitOMPTeamsDirective(OMPTeamsDirective *D) { + VisitStmt(D); + Record.push_back(D->getNumClauses()); + VisitOMPExecutableDirective(D); + Code = serialization::STMT_OMP_TEAMS_DIRECTIVE; +} + //===----------------------------------------------------------------------===// // ASTWriter Implementation //===----------------------------------------------------------------------===// diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index 7c1b7f504e..807d5216e8 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -818,6 +818,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::OMPOrderedDirectiveClass: case Stmt::OMPAtomicDirectiveClass: case Stmt::OMPTargetDirectiveClass: + case Stmt::OMPTeamsDirectiveClass: llvm_unreachable("Stmt should not be in analyzer evaluation loop"); case Stmt::ObjCSubscriptRefExprClass: diff --git a/test/OpenMP/nesting_of_regions.cpp b/test/OpenMP/nesting_of_regions.cpp index 0bc61f6e0d..a948ca3e3b 100644 --- a/test/OpenMP/nesting_of_regions.cpp +++ b/test/OpenMP/nesting_of_regions.cpp @@ -95,6 +95,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp parallel + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // SIMD DIRECTIVE #pragma omp simd @@ -217,6 +222,11 @@ void foo() { #pragma omp target // expected-error {{OpenMP constructs may not be nested inside a simd region}} ++a; } +#pragma omp simd + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside a simd region}} + ++a; + } // FOR DIRECTIVE #pragma omp for @@ -362,6 +372,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // FOR SIMD DIRECTIVE #pragma omp for simd @@ -484,6 +499,11 @@ void foo() { #pragma omp target // expected-error {{OpenMP constructs may not be nested inside a simd region}} ++a; } +#pragma omp for simd + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside a simd region}} + ++a; + } // SECTIONS DIRECTIVE #pragma omp sections @@ -636,6 +656,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp sections + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // SECTION DIRECTIVE #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} @@ -823,6 +848,12 @@ void foo() { #pragma omp target ++a; } +#pragma omp sections + { +#pragma omp section +#pragma omp teams // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // SINGLE DIRECTIVE #pragma omp single @@ -958,6 +989,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp single + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'single' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // MASTER DIRECTIVE #pragma omp master @@ -1093,6 +1129,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp master + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'master' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // CRITICAL DIRECTIVE #pragma omp critical @@ -1242,6 +1283,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp critical + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'critical' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // PARALLEL FOR DIRECTIVE #pragma omp parallel for @@ -1392,6 +1438,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // PARALLEL FOR SIMD DIRECTIVE #pragma omp parallel for simd @@ -1542,6 +1593,11 @@ void foo() { #pragma omp target // expected-error {{OpenMP constructs may not be nested inside a simd region}} ++a; } +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside a simd region}} + ++a; + } // PARALLEL SECTIONS DIRECTIVE #pragma omp parallel sections @@ -1683,6 +1739,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp parallel sections + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel sections' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // TASK DIRECTIVE #pragma omp task @@ -1770,6 +1831,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp task + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // ORDERED DIRECTIVE #pragma omp ordered @@ -1905,6 +1971,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp ordered + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'ordered' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // ATOMIC DIRECTIVE #pragma omp atomic @@ -2047,6 +2118,12 @@ void foo() { #pragma omp target // expected-error {{OpenMP constructs may not be nested inside an atomic region}} ++a; } +#pragma omp atomic + // 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}} + { +#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside an atomic region}} + ++a; + } // TARGET DIRECTIVE #pragma omp target @@ -2141,6 +2218,137 @@ void foo() { #pragma omp target ++a; } +#pragma omp target + { +#pragma omp teams + ++a; + } +#pragma omp target // expected-error {{target construct with nested teams region contains statements outside of the teams construct}} + { + ++a; // expected-note {{statement outside teams construct here}} +#pragma omp teams // expected-note {{nested teams construct here}} + ++a; + } + +// TEAMS DIRECTIVE +#pragma omp target +#pragma omp teams +#pragma omp parallel + bar(); +#pragma omp target +#pragma omp teams +#pragma omp for // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp simd // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp simd' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp for simd // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp for simd' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp sections // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}} + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a teams region}} + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp single // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + bar(); + +#pragma omp target +#pragma omp teams +#pragma omp master // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp master' directive into a parallel region?}} + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp critical // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp critical' directive into a parallel region?}} + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp parallel for + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp parallel sections + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp task // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp task' directive into a parallel region?}} + { + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp taskyield // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp taskyield' directive into a parallel region?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp barrier // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp barrier' directive into a parallel region?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp taskwait // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp taskwait' directive into a parallel region?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp flush // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp flush' directive into a parallel region?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp ordered // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp atomic // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp atomic' directive into a parallel region?}} + ++a; + } +#pragma omp target +#pragma omp teams + { +#pragma omp target // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp target' directive into a parallel region?}} + ++a; + } +#pragma omp target +#pragma omp teams + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } } void foo() { @@ -2235,6 +2443,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp parallel + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // SIMD DIRECTIVE #pragma omp simd @@ -2350,6 +2563,11 @@ void foo() { #pragma omp target // expected-error {{OpenMP constructs may not be nested inside a simd region}} ++a; } +#pragma omp simd + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside a simd region}} + ++a; + } // FOR DIRECTIVE #pragma omp for @@ -2485,6 +2703,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // FOR SIMD DIRECTIVE #pragma omp for simd @@ -2600,6 +2823,11 @@ void foo() { #pragma omp target // expected-error {{OpenMP constructs may not be nested inside a simd region}} ++a; } +#pragma omp for simd + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside a simd region}} + ++a; + } // SECTIONS DIRECTIVE #pragma omp sections @@ -2727,6 +2955,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp sections + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // SECTION DIRECTIVE #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} @@ -2918,6 +3151,14 @@ void foo() { ++a; } } +#pragma omp sections + { +#pragma omp section + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } + } // SINGLE DIRECTIVE #pragma omp single @@ -3043,6 +3284,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp single + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'single' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // MASTER DIRECTIVE #pragma omp master @@ -3178,6 +3424,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp master + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'master' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // CRITICAL DIRECTIVE #pragma omp critical @@ -3332,6 +3583,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp critical + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'critical' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // PARALLEL FOR DIRECTIVE #pragma omp parallel for @@ -3482,6 +3738,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // PARALLEL FOR SIMD DIRECTIVE #pragma omp parallel for simd @@ -3632,6 +3893,11 @@ void foo() { #pragma omp target // expected-error {{OpenMP constructs may not be nested inside a simd region}} ++a; } +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside a simd region}} + ++a; + } // PARALLEL SECTIONS DIRECTIVE #pragma omp parallel sections @@ -3769,6 +4035,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp parallel sections + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel sections' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // TASK DIRECTIVE #pragma omp task @@ -3855,6 +4126,11 @@ void foo() { #pragma omp target ++a; } +#pragma omp task + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } // ATOMIC DIRECTIVE #pragma omp atomic @@ -3997,6 +4273,12 @@ void foo() { #pragma omp target // expected-error {{OpenMP constructs may not be nested inside an atomic region}} ++a; } +#pragma omp atomic + // 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}} + { +#pragma omp teams // expected-error {{OpenMP constructs may not be nested inside an atomic region}} + ++a; + } // TARGET DIRECTIVE #pragma omp target @@ -4091,6 +4373,137 @@ void foo() { #pragma omp target ++a; } +#pragma omp target + { +#pragma omp teams + ++a; + } +#pragma omp target // expected-error {{target construct with nested teams region contains statements outside of the teams construct}} + { + ++a; // expected-note {{statement outside teams construct here}} +#pragma omp teams // expected-note {{nested teams construct here}} + ++a; + } + +// TEAMS DIRECTIVE +#pragma omp target +#pragma omp teams +#pragma omp parallel + bar(); +#pragma omp target +#pragma omp teams +#pragma omp for // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp simd // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp simd' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp for simd // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp for simd' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp sections // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}} + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a teams region}} + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp single // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + bar(); + +#pragma omp target +#pragma omp teams +#pragma omp master // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp master' directive into a parallel region?}} + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp critical // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp critical' directive into a parallel region?}} + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp parallel for + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp parallel sections + { + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp task // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp task' directive into a parallel region?}} + { + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp taskyield // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp taskyield' directive into a parallel region?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp barrier // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp barrier' directive into a parallel region?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp taskwait // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp taskwait' directive into a parallel region?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp flush // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp flush' directive into a parallel region?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp ordered // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + bar(); + } +#pragma omp target +#pragma omp teams + { +#pragma omp atomic // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp atomic' directive into a parallel region?}} + ++a; + } +#pragma omp target +#pragma omp teams + { +#pragma omp target // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp target' directive into a parallel region?}} + ++a; + } +#pragma omp target +#pragma omp teams + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } return foo(); } diff --git a/test/OpenMP/teams_ast_print.cpp b/test/OpenMP/teams_ast_print.cpp new file mode 100644 index 0000000000..394ec73a84 --- /dev/null +++ b/test/OpenMP/teams_ast_print.cpp @@ -0,0 +1,112 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ast-print %s | FileCheck %s +// RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp=libiomp5 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +void foo() {} + +template +struct S { + operator T() {return T();} + static T TS; + #pragma omp threadprivate(TS) +}; + +// CHECK: template struct S { +// CHECK: static int TS; +// CHECK-NEXT: #pragma omp threadprivate(S::TS) +// CHECK-NEXT: } +// CHECK: template struct S { +// CHECK: static long TS; +// CHECK-NEXT: #pragma omp threadprivate(S::TS) +// CHECK-NEXT: } +// CHECK: template struct S { +// CHECK: static T TS; +// CHECK-NEXT: #pragma omp threadprivate(S::TS) +// CHECK: }; + +template +T tmain(T argc, T *argv) { + T b = argc, c, d, e, f, g; + static T a; + S s; +#pragma omp target +#pragma omp teams + a=2; +#pragma omp target +#pragma omp teams default(none), private(argc,b) firstprivate(argv) shared (d) reduction(+:c) reduction(max:e) + foo(); +#pragma omp target +#pragma omp teams reduction(^:e, f) reduction(&& : g) + foo(); + return 0; +} + +// CHECK: template int tmain(int argc, int *argv) { +// CHECK-NEXT: int b = argc, c, d, e, f, g; +// CHECK-NEXT: static int a; +// CHECK-NEXT: S s; +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams +// CHECK-NEXT: a = 2; +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) +// CHECK-NEXT: foo() +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams reduction(^: e,f) reduction(&&: g) +// CHECK-NEXT: foo() +// CHECK: template long tmain(long argc, long *argv) { +// CHECK-NEXT: long b = argc, c, d, e, f, g; +// CHECK-NEXT: static long a; +// CHECK-NEXT: S s; +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams +// CHECK-NEXT: a = 2; +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) +// CHECK-NEXT: foo() +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams reduction(^: e,f) reduction(&&: g) +// CHECK-NEXT: foo() +// CHECK: template T tmain(T argc, T *argv) { +// CHECK-NEXT: T b = argc, c, d, e, f, g; +// CHECK-NEXT: static T a; +// CHECK-NEXT: S s; +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams +// CHECK-NEXT: a = 2; +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) shared(d) reduction(+: c) reduction(max: e) +// CHECK-NEXT: foo() +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams reduction(^: e,f) reduction(&&: g) +// CHECK-NEXT: foo() + +enum Enum { }; + +int main (int argc, char **argv) { + long x; + int b = argc, c, d, e, f, g; + static int a; + #pragma omp threadprivate(a) + Enum ee; +// CHECK: Enum ee; +#pragma omp target +#pragma omp teams +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams + a=2; +// CHECK-NEXT: a = 2; +#pragma omp target +#pragma omp teams default(none), private(argc,b) firstprivate(argv) reduction(| : c, d) reduction(* : e) +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams default(none) private(argc,b) firstprivate(argv) reduction(|: c,d) reduction(*: e) + foo(); +// CHECK-NEXT: foo(); + return tmain(b, &b) + tmain(x, &x); +} + +#endif diff --git a/test/OpenMP/teams_default_messages.cpp b/test/OpenMP/teams_default_messages.cpp new file mode 100644 index 0000000000..4f5a267150 --- /dev/null +++ b/test/OpenMP/teams_default_messages.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -o - %s + +void foo(); + +int main(int argc, char **argv) { + #pragma omp target + #pragma omp teams default // expected-error {{expected '(' after 'default'}} + foo(); + #pragma omp target + #pragma omp teams default ( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams default () // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} + foo(); + #pragma omp target + #pragma omp teams default (none // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams default (shared), default(shared) // expected-error {{directive '#pragma omp teams' cannot contain more than one 'default' clause}} + foo(); + #pragma omp target + #pragma omp teams default (x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} + foo(); + + #pragma omp target + #pragma omp teams default(none) + ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} + + #pragma omp target + #pragma omp teams default(none) + #pragma omp parallel default(shared) + ++argc; + return 0; +} diff --git a/test/OpenMP/teams_firstprivate_messages.cpp b/test/OpenMP/teams_firstprivate_messages.cpp new file mode 100644 index 0000000000..67728f7ef9 --- /dev/null +++ b/test/OpenMP/teams_firstprivate_messages.cpp @@ -0,0 +1,122 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; +public: + S2():a(0) { } + S2(S2 &s2):a(s2.a) { } + static float S2s; + static const float S2sc; +}; +const float S2::S2sc = 0; +const S2 b; +const S2 ba[5]; +class S3 { + int a; +public: + S3():a(0) { } + S3(S3 &s3):a(s3.a) { } +}; +const S3 c; +const S3 ca[5]; +extern const int f; +class S4 { // expected-note {{'S4' declared here}} + int a; + S4(); + S4(const S4 &s4); +public: + S4(int v):a(v) { } +}; +class S5 { // expected-note {{'S5' declared here}} + int a; + S5():a(0) {} + S5(const S5 &s5):a(s5.a) { } +public: + S5(int v):a(v) { } +}; + +S3 h; +#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}} + +int main(int argc, char **argv) { + const int d = 5; + const int da[5] = { 0 }; + S4 e(4); // expected-note {{'e' defined here}} + S5 g(5); // expected-note {{'g' defined here}} + int i; + int &j = i; // expected-note {{'j' defined here}} + #pragma omp target + #pragma omp teams firstprivate // expected-error {{expected '(' after 'firstprivate'}} + foo(); + #pragma omp target + #pragma omp teams firstprivate ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams firstprivate () // expected-error {{expected expression}} + foo(); + #pragma omp target + #pragma omp teams firstprivate (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams firstprivate (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams firstprivate (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + foo(); + #pragma omp target + #pragma omp teams firstprivate (argc) + foo(); + #pragma omp target + #pragma omp teams firstprivate (S1) // expected-error {{'S1' does not refer to a value}} + foo(); + #pragma omp target + #pragma omp teams firstprivate (a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} + foo(); + #pragma omp target + #pragma omp teams firstprivate (argv[1]) // expected-error {{expected variable name}} + foo(); + #pragma omp target + #pragma omp teams firstprivate(ba) + foo(); + #pragma omp target + #pragma omp teams firstprivate(ca) + foo(); + #pragma omp target + #pragma omp teams firstprivate(da) + foo(); + #pragma omp target + #pragma omp teams firstprivate(S2::S2s) + foo(); + #pragma omp target + #pragma omp teams firstprivate(S2::S2sc) + foo(); + #pragma omp target + #pragma omp teams firstprivate(e, g) // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}} + foo(); + #pragma omp target + #pragma omp teams firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} + foo(); + #pragma omp target + #pragma omp teams private(i), firstprivate(i) // expected-error {{private variable cannot be firstprivate}} expected-note{{defined as private}} + foo(); + #pragma omp target + #pragma omp teams shared(i) + foo(); + #pragma omp target + #pragma omp teams firstprivate(i) + foo(); + #pragma omp target + #pragma omp teams firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}} + foo(); + + return 0; +} diff --git a/test/OpenMP/teams_messages.cpp b/test/OpenMP/teams_messages.cpp new file mode 100644 index 0000000000..56ed548a03 --- /dev/null +++ b/test/OpenMP/teams_messages.cpp @@ -0,0 +1,82 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -std=c++11 -o - %s + +void foo() { +} + +#pragma omp teams // expected-error {{unexpected OpenMP directive '#pragma omp teams'}} + +int main(int argc, char **argv) { + #pragma omp target + #pragma omp teams { // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); + #pragma omp target + #pragma omp teams ( // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); + #pragma omp target + #pragma omp teams [ // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); + #pragma omp target + #pragma omp teams ] // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); + #pragma omp target + #pragma omp teams ) // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); + #pragma omp target + #pragma omp teams } // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); + #pragma omp target + #pragma omp teams + foo(); + // expected-warning@+2 {{extra tokens at the end of '#pragma omp teams' are ignored}} + #pragma omp target + #pragma omp teams unknown() + foo(); + L1: + foo(); + #pragma omp target + #pragma omp teams + ; + #pragma omp target + #pragma omp teams + { + goto L1; // expected-error {{use of undeclared label 'L1'}} + argc++; + } + + for (int i = 0; i < 10; ++i) { + switch(argc) { + case (0): + #pragma omp target + #pragma omp teams + { + foo(); + break; // expected-error {{'break' statement not in loop or switch statement}} + continue; // expected-error {{'continue' statement not in loop statement}} + } + default: + break; + } + } + #pragma omp target + #pragma omp teams default(none) + ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} + + goto L2; // expected-error {{use of undeclared label 'L2'}} + #pragma omp target + #pragma omp teams + L2: + foo(); + #pragma omp target + #pragma omp teams + { + return 1; // expected-error {{cannot return from OpenMP region}} + } + + [[]] // expected-error {{an attribute list cannot appear here}} + #pragma omp target + #pragma omp teams + for (int n = 0; n < 100; ++n) {} + + return 0; +} + diff --git a/test/OpenMP/teams_private_messages.cpp b/test/OpenMP/teams_private_messages.cpp new file mode 100644 index 0000000000..c461b26e26 --- /dev/null +++ b/test/OpenMP/teams_private_messages.cpp @@ -0,0 +1,119 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; +public: + S2():a(0) { } + static float S2s; // expected-note {{static data member is predetermined as shared}} +}; +const S2 b; +const S2 ba[5]; +class S3 { + int a; +public: + S3():a(0) { } +}; +const S3 c; // expected-note {{global variable is predetermined as shared}} +const S3 ca[5]; // expected-note {{global variable is predetermined as shared}} +extern const int f; // expected-note {{global variable is predetermined as shared}} +class S4 { // expected-note {{'S4' declared here}} + int a; + S4(); +public: + S4(int v):a(v) { } +}; +class S5 { // expected-note {{'S5' declared here}} + int a; + S5():a(0) {} +public: + S5(int v):a(v) { } +}; + +int threadvar; +#pragma omp threadprivate(threadvar) // expected-note {{defined as threadprivate or thread local}} + +int main(int argc, char **argv) { + const int d = 5; // expected-note {{constant variable is predetermined as shared}} + const int da[5] = { 0 }; // expected-note {{constant variable is predetermined as shared}} + S4 e(4); // expected-note {{'e' defined here}} + S5 g(5); // expected-note {{'g' defined here}} + int i; + int &j = i; // expected-note {{'j' defined here}} + #pragma omp target + #pragma omp teams private // expected-error {{expected '(' after 'private'}} + foo(); + #pragma omp target + #pragma omp teams private ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams private () // expected-error {{expected expression}} + foo(); + #pragma omp target + #pragma omp teams private (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams private (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams private (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + foo(); + #pragma omp target + #pragma omp teams private (argc argv) // expected-error {{expected ',' or ')' in 'private' clause}} + foo(); + #pragma omp target + #pragma omp teams private (S1) // expected-error {{'S1' does not refer to a value}} + foo(); + #pragma omp target + #pragma omp teams private (a, b, c, d, f) // expected-error {{a private variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be private}} + foo(); + #pragma omp target + #pragma omp teams private (argv[1]) // expected-error {{expected variable name}} + foo(); + #pragma omp target + #pragma omp teams private(ba) + foo(); + #pragma omp target + #pragma omp teams private(ca) // expected-error {{shared variable cannot be private}} + foo(); + #pragma omp target + #pragma omp teams private(da) // expected-error {{shared variable cannot be private}} + foo(); + #pragma omp target + #pragma omp teams private(S2::S2s) // expected-error {{shared variable cannot be private}} + foo(); + #pragma omp target + #pragma omp teams private(e, g) // expected-error 2 {{private variable must have an accessible, unambiguous default constructor}} + foo(); + #pragma omp target + #pragma omp teams private(threadvar) // expected-error {{threadprivate or thread local variable cannot be private}} + foo(); + #pragma omp target + #pragma omp teams shared(i), private(i) // expected-error {{shared variable cannot be private}} expected-note {{defined as shared}} + foo(); + #pragma omp target + #pragma omp teams firstprivate(i) private(i) // expected-error {{firstprivate variable cannot be private}} expected-note {{defined as firstprivate}} + foo(); + #pragma omp target + #pragma omp teams private(i) + foo(); + #pragma omp target + #pragma omp teams private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type 'int &'}} + foo(); + #pragma omp target + #pragma omp teams firstprivate(i) + for (int k = 0; k < 10; ++k) { + #pragma omp parallel private(i) + foo(); + } + + return 0; +} diff --git a/test/OpenMP/teams_reduction_messages.cpp b/test/OpenMP/teams_reduction_messages.cpp new file mode 100644 index 0000000000..afedfc3e46 --- /dev/null +++ b/test/OpenMP/teams_reduction_messages.cpp @@ -0,0 +1,307 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -o - %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; + S2 &operator+=(const S2 &arg) { return (*this); } + +public: + S2() : a(0) {} + S2(S2 &s2) : a(s2.a) {} + static float S2s; // expected-note 2 {{static data member is predetermined as shared}} + static const float S2sc; +}; +const float S2::S2sc = 0; // expected-note 2 {{'S2sc' defined here}} +S2 b; // expected-note 2 {{'b' defined here}} +const S2 ba[5]; // expected-note 2 {{'ba' defined here}} +class S3 { + int a; + +public: + S3() : a(0) {} + S3(const S3 &s3) : a(s3.a) {} + S3 operator+=(const S3 &arg1) { return arg1; } +}; +int operator+=(const S3 &arg1, const S3 &arg2) { return 5; } +S3 c; // expected-note 2 {{'c' defined here}} +const S3 ca[5]; // expected-note 2 {{'ca' defined here}} +extern const int f; // expected-note 4 {{'f' declared here}} +class S4 { // expected-note {{'S4' declared here}} + int a; + S4(); + S4(const S4 &s4); + S4 &operator+=(const S4 &arg) { return (*this); } + +public: + S4(int v) : a(v) {} +}; +S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; } +class S5 { + int a; + S5() : a(0) {} + S5(const S5 &s5) : a(s5.a) {} + S5 &operator+=(const S5 &arg); + +public: + S5(int v) : a(v) {} +}; +class S6 { + int a; + +public: + S6() : a(6) {} + operator int() { return 6; } +} o; // expected-note 2 {{'o' defined here}} + +S3 h, k; +#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} + +template // expected-note {{declared here}} +T tmain(T argc) { // expected-note 2 {{'argc' defined here}} + const T d = T(); // expected-note 4 {{'d' defined here}} + const T da[5] = {T()}; // expected-note 2 {{'da' defined here}} + T qa[5] = {T()}; + T i; + T &j = i; // expected-note 4 {{'j' defined here}} + S3 &p = k; // expected-note 2 {{'p' defined here}} + const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}} + T &q = qa[(int)i]; // expected-note 2 {{'q' defined here}} + T fl; // expected-note {{'fl' defined here}} +#pragma omp target +#pragma omp teams reduction // expected-error {{expected '(' after 'reduction'}} + foo(); +#pragma omp target +#pragma omp teams reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); +#pragma omp target +#pragma omp teams reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp target +#pragma omp teams reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp target +#pragma omp teams reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} + foo(); +#pragma omp target +#pragma omp teams reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} + foo(); +#pragma omp target +#pragma omp teams reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} + foo(); +#pragma omp target +#pragma omp teams reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{variable of type 'float' is not valid for specified reduction operation}} + foo(); +#pragma omp target +#pragma omp teams reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{variable of type 'float' is not valid for specified reduction operation}} + foo(); +#pragma omp target +#pragma omp teams reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name}} + foo(); +#pragma omp target +#pragma omp teams reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}} + foo(); +#pragma omp target +#pragma omp teams reduction(&& : argc) + foo(); +#pragma omp target +#pragma omp teams reduction(^ : T) // expected-error {{'T' does not refer to a value}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : a, b, c, d, f) // expected-error {{reduction variable with incomplete type 'S1'}} expected-error 3 {{const-qualified variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(min : a, b, c, d, f) // expected-error {{reduction variable with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 3 {{const-qualified variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(max : qa[1]) // expected-error 2 {{expected variable name}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : ba) // expected-error {{a reduction variable with array type 'const S2 [5]'}} + foo(); +#pragma omp target +#pragma omp teams reduction(* : ca) // expected-error {{a reduction variable with array type 'const S3 [5]'}} + foo(); +#pragma omp target +#pragma omp teams reduction(- : da) // expected-error {{a reduction variable with array type 'const int [5]'}} expected-error {{a reduction variable with array type 'const float [5]'}} + foo(); +#pragma omp target +#pragma omp teams reduction(^ : fl) // expected-error {{variable of type 'float' is not valid for specified reduction operation}} + foo(); +#pragma omp target +#pragma omp teams reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : o) // expected-error {{variable of type 'class S6' is not valid for specified reduction operation}} + foo(); +#pragma omp target +#pragma omp teams private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + foo(); +#pragma omp parallel private(k) +#pragma omp target +#pragma omp teams reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : p), reduction(+ : p) // expected-error 3 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 3 {{previously referenced here}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : r) // expected-error 2 {{const-qualified variable cannot be reduction}} + foo(); +#pragma omp parallel shared(i) +#pragma omp parallel reduction(min : i) +#pragma omp target +#pragma omp teams reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + foo(); +#pragma omp target +#pragma omp teams +#pragma omp parallel for private(fl) + for (int i = 0; i < 10; ++i) +#pragma omp target +#pragma omp teams reduction(+ : fl) + foo(); +#pragma omp target +#pragma omp teams +#pragma omp parallel for reduction(- : fl) + for (int i = 0; i < 10; ++i) +#pragma omp target +#pragma omp teams reduction(+ : fl) + foo(); + + return T(); +} + +int main(int argc, char **argv) { + const int d = 5; // expected-note 2 {{'d' defined here}} + const int da[5] = {0}; // expected-note {{'da' defined here}} + int qa[5] = {0}; + S4 e(4); // expected-note {{'e' defined here}} + S5 g(5); // expected-note {{'g' defined here}} + int i; + int &j = i; // expected-note 2 {{'j' defined here}} + S3 &p = k; // expected-note 2 {{'p' defined here}} + const int &r = da[i]; // expected-note {{'r' defined here}} + int &q = qa[i]; // expected-note {{'q' defined here}} + float fl; // expected-note {{'fl' defined here}} +#pragma omp target +#pragma omp teams reduction // expected-error {{expected '(' after 'reduction'}} + foo(); +#pragma omp target +#pragma omp teams reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}} + foo(); +#pragma omp target +#pragma omp teams reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp target +#pragma omp teams reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp target +#pragma omp teams reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} + foo(); +#pragma omp target +#pragma omp teams reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} + foo(); +#pragma omp target +#pragma omp teams reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} + foo(); +#pragma omp target +#pragma omp teams reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}} + foo(); +#pragma omp target +#pragma omp teams reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp target +#pragma omp teams reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + foo(); +#pragma omp target +#pragma omp teams reduction(~ : argc) // expected-error {{expected unqualified-id}} + foo(); +#pragma omp target +#pragma omp teams reduction(&& : argc) + foo(); +#pragma omp target +#pragma omp teams reduction(^ : S1) // expected-error {{'S1' does not refer to a value}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : a, b, c, d, f) // expected-error {{reduction variable with incomplete type 'S1'}} expected-error 2 {{const-qualified variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(min : a, b, c, d, f) // expected-error {{reduction variable with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 2 {{const-qualified variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(max : argv[1]) // expected-error {{expected variable name}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : ba) // expected-error {{a reduction variable with array type 'const S2 [5]'}} + foo(); +#pragma omp target +#pragma omp teams reduction(* : ca) // expected-error {{a reduction variable with array type 'const S3 [5]'}} + foo(); +#pragma omp target +#pragma omp teams reduction(- : da) // expected-error {{a reduction variable with array type 'const int [5]'}} + foo(); +#pragma omp target +#pragma omp teams reduction(^ : fl) // expected-error {{variable of type 'float' is not valid for specified reduction operation}} + foo(); +#pragma omp target +#pragma omp teams reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(& : e, g) // expected-error {{reduction variable must have an accessible, unambiguous default constructor}} expected-error {{variable of type 'S5' is not valid for specified reduction operation}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : o) // expected-error {{variable of type 'class S6' is not valid for specified reduction operation}} + foo(); +#pragma omp target +#pragma omp teams private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + foo(); +#pragma omp parallel private(k) +#pragma omp target +#pragma omp teams reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}} + foo(); +#pragma omp target +#pragma omp teams reduction(+ : r) // expected-error {{const-qualified variable cannot be reduction}} + foo(); +#pragma omp parallel shared(i) +#pragma omp parallel reduction(min : i) +#pragma omp target +#pragma omp teams reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + foo(); +#pragma omp target +#pragma omp teams +#pragma omp parallel for private(fl) + for (int i = 0; i < 10; ++i) +#pragma omp target +#pragma omp teams reduction(+ : fl) + foo(); +#pragma omp target +#pragma omp teams +#pragma omp parallel for reduction(- : fl) + for (int i = 0; i < 10; ++i) +#pragma omp target +#pragma omp teams reduction(+ : fl) + foo(); + + return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain' requested here}} expected-note {{in instantiation of function template specialization 'tmain' requested here}} +} diff --git a/test/OpenMP/teams_shared_messages.cpp b/test/OpenMP/teams_shared_messages.cpp new file mode 100644 index 0000000000..ce2f917e20 --- /dev/null +++ b/test/OpenMP/teams_shared_messages.cpp @@ -0,0 +1,125 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} +extern S1 a; +class S2 { + mutable int a; +public: + S2():a(0) { } + S2(S2 &s2):a(s2.a) { } +}; +const S2 b; +const S2 ba[5]; +class S3 { + int a; +public: + S3():a(0) { } + S3(S3 &s3):a(s3.a) { } +}; +const S3 c; +const S3 ca[5]; +extern const int f; +class S4 { + int a; + S4(); + S4(const S4 &s4); +public: + S4(int v):a(v) { } +}; +class S5 { + int a; + S5():a(0) {} + S5(const S5 &s5):a(s5.a) { } +public: + S5(int v):a(v) { } +}; + +S3 h; +#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}} + +int main(int argc, char **argv) { + const int d = 5; + const int da[5] = { 0 }; + S4 e(4); + S5 g(5); + int i; + int &j = i; + #pragma omp target + #pragma omp teams shared // expected-error {{expected '(' after 'shared'}} + foo(); + #pragma omp target + #pragma omp teams shared ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams shared () // expected-error {{expected expression}} + foo(); + #pragma omp target + #pragma omp teams shared (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams shared (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); + #pragma omp target + #pragma omp teams shared (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + foo(); + #pragma omp target + #pragma omp teams shared (argc) + foo(); + #pragma omp target + #pragma omp teams shared (S1) // expected-error {{'S1' does not refer to a value}} + foo(); + #pragma omp target + #pragma omp teams shared (a, b, c, d, f) + foo(); + #pragma omp target + #pragma omp teams shared (argv[1]) // expected-error {{expected variable name}} + foo(); + #pragma omp target + #pragma omp teams shared(ba) + foo(); + #pragma omp target + #pragma omp teams shared(ca) + foo(); + #pragma omp target + #pragma omp teams shared(da) + foo(); + #pragma omp target + #pragma omp teams shared(e, g) + foo(); + #pragma omp target + #pragma omp teams shared(h) // expected-error {{threadprivate or thread local variable cannot be shared}} + foo(); + #pragma omp target + #pragma omp teams private(i), shared(i) // expected-error {{private variable cannot be shared}} expected-note {{defined as private}} + foo(); + #pragma omp target + #pragma omp teams firstprivate(i), shared(i) // expected-error {{firstprivate variable cannot be shared}} expected-note {{defined as firstprivate}} + foo(); + #pragma omp target + #pragma omp teams private(i) + foo(); + #pragma omp target + #pragma omp teams shared(i) + foo(); + #pragma omp target + #pragma omp teams shared(j) + foo(); + #pragma omp target + #pragma omp teams firstprivate(i) + foo(); + #pragma omp target + #pragma omp teams shared(i) + foo(); + #pragma omp target + #pragma omp teams shared(j) + foo(); + + return 0; +} diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index df696b1cdf..eab289206e 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1883,6 +1883,7 @@ public: void VisitOMPOrderedDirective(const OMPOrderedDirective *D); void VisitOMPAtomicDirective(const OMPAtomicDirective *D); void VisitOMPTargetDirective(const OMPTargetDirective *D); + void VisitOMPTeamsDirective(const OMPTeamsDirective *D); private: void AddDeclarationNameInfo(const Stmt *S); @@ -2420,6 +2421,10 @@ void EnqueueVisitor::VisitOMPTargetDirective(const OMPTargetDirective *D) { VisitOMPExecutableDirective(D); } +void EnqueueVisitor::VisitOMPTeamsDirective(const OMPTeamsDirective *D) { + VisitOMPExecutableDirective(D); +} + void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) { EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S); } @@ -4189,6 +4194,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { return cxstring::createRef("OMPAtomicDirective"); case CXCursor_OMPTargetDirective: return cxstring::createRef("OMPTargetDirective"); + case CXCursor_OMPTeamsDirective: + return cxstring::createRef("OMPTeamsDirective"); } llvm_unreachable("Unhandled CXCursorKind"); diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index 05117ef035..782f05e1e8 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -578,6 +578,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent, case Stmt::OMPTargetDirectiveClass: K = CXCursor_OMPTargetDirective; break; + case Stmt::OMPTeamsDirectiveClass: + K = CXCursor_OMPTeamsDirective; + break; } CXCursor C = { K, 0, { Parent, S, TU } };