From: Alexey Bataev Date: Fri, 18 Jul 2014 10:17:07 +0000 (+0000) Subject: [OPENMP] Initial parsing and sema analysis for 'taskwait' directive. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=570d14de3d677f04093d23230ed2e864f5d4cd48;p=clang [OPENMP] Initial parsing and sema analysis for 'taskwait' directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213363 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 22882bb91e..7b808419a6 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -2179,9 +2179,13 @@ enum CXCursorKind { */ CXCursor_OMPBarrierDirective = 243, + /** \brief OpenMP taskwait directive. + */ + CXCursor_OMPTaskwaitDirective = 244, + /** \brief Windows Structured Exception Handling's leave statement. */ - CXCursor_SEHLeaveStmt = 244, + CXCursor_SEHLeaveStmt = 245, CXCursor_LastStmt = CXCursor_SEHLeaveStmt, diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 2eb05a5cbf..ea3bb17114 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -2315,6 +2315,9 @@ DEF_TRAVERSE_STMT(OMPTaskyieldDirective, DEF_TRAVERSE_STMT(OMPBarrierDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) +DEF_TRAVERSE_STMT(OMPTaskwaitDirective, + { 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 c5ec97615e..e176a5fe0a 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2337,6 +2337,9 @@ DEF_TRAVERSE_STMT(OMPTaskyieldDirective, DEF_TRAVERSE_STMT(OMPBarrierDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) +DEF_TRAVERSE_STMT(OMPTaskwaitDirective, + { 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 f4445b6cfe..62af6a2444 100644 --- a/include/clang/AST/StmtOpenMP.h +++ b/include/clang/AST/StmtOpenMP.h @@ -862,6 +862,50 @@ public: } }; +/// \brief This represents '#pragma omp taskwait' directive. +/// +/// \code +/// #pragma omp taskwait +/// \endcode +/// +class OMPTaskwaitDirective : 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. + /// + OMPTaskwaitDirective(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, OMPD_taskwait, + StartLoc, EndLoc, 0, 0) {} + + /// \brief Build an empty directive. + /// + explicit OMPTaskwaitDirective() + : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, OMPD_taskwait, + SourceLocation(), SourceLocation(), 0, 0) {} + +public: + /// \brief Creates directive. + /// + /// \param C AST context. + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending Location of the directive. + /// + static OMPTaskwaitDirective * + Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc); + + /// \brief Creates an empty directive. + /// + /// \param C AST context. + /// + static OMPTaskwaitDirective *CreateEmpty(const ASTContext &C, EmptyShell); + + static bool classof(const Stmt *T) { + return T->getStmtClass() == OMPTaskwaitDirectiveClass; + } +}; + } // end namespace clang #endif diff --git a/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def index 12d0674d70..f43a8b5cf7 100644 --- a/include/clang/Basic/OpenMPKinds.def +++ b/include/clang/Basic/OpenMPKinds.def @@ -67,6 +67,7 @@ OPENMP_DIRECTIVE(single) OPENMP_DIRECTIVE(master) OPENMP_DIRECTIVE(taskyield) OPENMP_DIRECTIVE(barrier) +OPENMP_DIRECTIVE(taskwait) OPENMP_DIRECTIVE_EXT(parallel_for, "parallel for") OPENMP_DIRECTIVE_EXT(parallel_sections, "parallel sections") diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td index 88a166a770..fd4546ac9e 100644 --- a/include/clang/Basic/StmtNodes.td +++ b/include/clang/Basic/StmtNodes.td @@ -190,3 +190,4 @@ def OMPParallelSectionsDirective : DStmt; def OMPTaskDirective : DStmt; def OMPTaskyieldDirective : DStmt; def OMPBarrierDirective : DStmt; +def OMPTaskwaitDirective : DStmt; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index bfe6b2d193..8ecffb6f3c 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -7374,6 +7374,9 @@ public: /// \brief Called on well-formed '\#pragma omp barrier'. StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc, SourceLocation EndLoc); + /// \brief Called on well-formed '\#pragma omp taskwait'. + StmtResult ActOnOpenMPTaskwaitDirective(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 f567925944..ae7f44b7a7 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -1352,6 +1352,7 @@ namespace clang { STMT_OMP_TASK_DIRECTIVE, STMT_OMP_TASKYIELD_DIRECTIVE, STMT_OMP_BARRIER_DIRECTIVE, + STMT_OMP_TASKWAIT_DIRECTIVE, // ARC EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 2328d27b9c..e46edd23ec 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -1603,3 +1603,17 @@ OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C, return new (Mem) OMPBarrierDirective(); } +OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C, + SourceLocation StartLoc, + SourceLocation EndLoc) { + void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); + OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc); + return Dir; +} + +OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C, + EmptyShell) { + void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); + return new (Mem) OMPTaskwaitDirective(); +} + diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 02f09c4a5a..0267bcca2a 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -860,6 +860,11 @@ void StmtPrinter::VisitOMPBarrierDirective(OMPBarrierDirective *Node) { PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *Node) { + Indent() << "#pragma omp taskwait"; + PrintOMPExecutableDirective(Node); +} + //===----------------------------------------------------------------------===// // Expr printing methods. //===----------------------------------------------------------------------===// diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index ae3be8dc1a..0cd0f62dc5 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -415,6 +415,10 @@ void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) { VisitOMPExecutableDirective(S); } +void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) { + VisitOMPExecutableDirective(S); +} + void StmtProfiler::VisitExpr(const Expr *S) { VisitStmt(S); } diff --git a/lib/Basic/OpenMPKinds.cpp b/lib/Basic/OpenMPKinds.cpp index ec2e6b4e0e..f304513fcc 100644 --- a/lib/Basic/OpenMPKinds.cpp +++ b/lib/Basic/OpenMPKinds.cpp @@ -259,6 +259,7 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, case OMPD_master: case OMPD_taskyield: case OMPD_barrier: + case OMPD_taskwait: break; } return false; diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 5da12222fc..cd970c747c 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -212,6 +212,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::OMPBarrierDirectiveClass: EmitOMPBarrierDirective(cast(*S)); break; + case Stmt::OMPTaskwaitDirectiveClass: + EmitOMPTaskwaitDirective(cast(*S)); + break; } } diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index db9daefbac..7731c76f51 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -116,3 +116,7 @@ void CodeGenFunction::EmitOMPBarrierDirective(const OMPBarrierDirective &) { llvm_unreachable("CodeGen for 'omp barrier' is not supported yet."); } +void CodeGenFunction::EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &) { + llvm_unreachable("CodeGen for 'omp taskwait' is not supported yet."); +} + diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index f0541f5bf1..3692b0203f 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1933,6 +1933,7 @@ public: void EmitOMPTaskDirective(const OMPTaskDirective &S); void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S); void EmitOMPBarrierDirective(const OMPBarrierDirective &S); + void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S); //===--------------------------------------------------------------------===// // LValue Expression Emission diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index b3f13b8bff..cf99178430 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -85,6 +85,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { case OMPD_task: case OMPD_taskyield: case OMPD_barrier: + case OMPD_taskwait: case OMPD_for: case OMPD_sections: case OMPD_section: @@ -109,8 +110,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { /// executable-directive: /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | /// 'section' | 'single' | 'master' | 'parallel for' | -/// 'parallel sections' | 'task' | 'taskyield' | 'barrier' {clause} -/// annot_pragma_openmp_end +/// 'parallel sections' | 'task' | 'taskyield' | 'barrier' | 'taskwait' +/// {clause} annot_pragma_openmp_end /// StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) { @@ -148,6 +149,7 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) { break; case OMPD_taskyield: case OMPD_barrier: + case OMPD_taskwait: if (!StandAloneAllowed) { Diag(Tok, diag::err_omp_immediate_directive) << getOpenMPDirectiveName(DKind); diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 01abf5f63c..6f6c495dde 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -804,7 +804,6 @@ StmtResult Parser::ParseCompoundStatement(bool isStmtExpr) { /// declaration /// [GNU] '__extension__' declaration /// statement -/// [OMP] openmp-directive [TODO] /// /// [GNU] label-declarations: /// [GNU] label-declaration @@ -813,10 +812,6 @@ StmtResult Parser::ParseCompoundStatement(bool isStmtExpr) { /// [GNU] label-declaration: /// [GNU] '__label__' identifier-list ';' /// -/// [OMP] openmp-directive: [TODO] -/// [OMP] barrier-directive -/// [OMP] flush-directive -/// StmtResult Parser::ParseCompoundStatement(bool isStmtExpr, unsigned ScopeFlags) { assert(Tok.is(tok::l_brace) && "Not a compount stmt!"); diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index eeb4fbd752..f2421da582 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -1052,6 +1052,14 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { Params); break; } + case OMPD_taskwait: { + Sema::CapturedParamNameType Params[] = { + 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: @@ -1078,6 +1086,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel | task | * | // | parallel | taskyield | * | // | parallel | barrier | * | + // | parallel | taskwait | * | // +------------------+-----------------+------------------------------------+ // | for | parallel | * | // | for | for | + | @@ -1091,6 +1100,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for | task | * | // | for | taskyield | * | // | for | barrier | + | + // | for | taskwait | * | // +------------------+-----------------+------------------------------------+ // | master | parallel | * | // | master | for | + | @@ -1104,6 +1114,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | master | task | * | // | master | taskyield | * | // | master | barrier | + | + // | master | taskwait | * | // +------------------+-----------------+------------------------------------+ // | simd | parallel | | // | simd | for | | @@ -1117,6 +1128,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | simd | task | | // | simd | taskyield | | // | simd | barrier | | + // | simd | taskwait | | // +------------------+-----------------+------------------------------------+ // | sections | parallel | * | // | sections | for | + | @@ -1130,6 +1142,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | sections | task | * | // | sections | taskyield | * | // | sections | barrier | + | + // | sections | taskwait | * | // +------------------+-----------------+------------------------------------+ // | section | parallel | * | // | section | for | + | @@ -1143,6 +1156,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | section | task | * | // | section | taskyield | * | // | section | barrier | + | + // | section | taskwait | * | // +------------------+-----------------+------------------------------------+ // | single | parallel | * | // | single | for | + | @@ -1156,6 +1170,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | single | task | * | // | single | taskyield | * | // | single | barrier | + | + // | single | taskwait | * | // +------------------+-----------------+------------------------------------+ // | parallel for | parallel | * | // | parallel for | for | + | @@ -1169,6 +1184,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for | task | * | // | parallel for | taskyield | * | // | parallel for | barrier | + | + // | parallel for | taskwait | * | // +------------------+-----------------+------------------------------------+ // | parallel sections| parallel | * | // | parallel sections| for | + | @@ -1182,6 +1198,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel sections| task | * | // | parallel sections| taskyield | * | // | parallel sections| barrier | + | + // | parallel sections| taskwait | * | // +------------------+-----------------+------------------------------------+ // | task | parallel | * | // | task | for | + | @@ -1195,6 +1212,7 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | task | task | * | // | task | taskyield | * | // | task | barrier | + | + // | task | taskwait | * | // +------------------+-----------------+------------------------------------+ if (Stack->getCurScope()) { auto ParentRegion = Stack->getParentDirective(); @@ -1351,6 +1369,13 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, "No associated statement allowed for 'omp barrier' directive"); Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); break; + case OMPD_taskwait: + assert(ClausesWithImplicit.empty() && + "No clauses are allowed for 'omp taskwait' directive"); + assert(AStmt == nullptr && + "No associated statement allowed for 'omp taskwait' directive"); + Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); + break; case OMPD_threadprivate: llvm_unreachable("OpenMP Directive is not allowed"); case OMPD_unknown: @@ -2104,6 +2129,11 @@ StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); } +StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, + SourceLocation EndLoc) { + return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); +} + OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, SourceLocation StartLoc, SourceLocation LParenLoc, diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index a562bfd616..04a3909da3 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -6579,6 +6579,17 @@ TreeTransform::TransformOMPBarrierDirective(OMPBarrierDirective *D) { return Res; } +template +StmtResult +TreeTransform::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, 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 9c6707a750..99c9827ae2 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -2000,6 +2000,11 @@ void ASTStmtReader::VisitOMPBarrierDirective(OMPBarrierDirective *D) { VisitOMPExecutableDirective(D); } +void ASTStmtReader::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) { + VisitStmt(D); + VisitOMPExecutableDirective(D); +} + //===----------------------------------------------------------------------===// // ASTReader Implementation //===----------------------------------------------------------------------===// @@ -2542,6 +2547,10 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { S = OMPBarrierDirective::CreateEmpty(Context, Empty); break; + case STMT_OMP_TASKWAIT_DIRECTIVE: + S = OMPTaskwaitDirective::CreateEmpty(Context, 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 204c18a4e7..db6adbcbaa 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -1903,6 +1903,12 @@ void ASTStmtWriter::VisitOMPBarrierDirective(OMPBarrierDirective *D) { Code = serialization::STMT_OMP_BARRIER_DIRECTIVE; } +void ASTStmtWriter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) { + VisitStmt(D); + VisitOMPExecutableDirective(D); + Code = serialization::STMT_OMP_TASKWAIT_DIRECTIVE; +} + //===----------------------------------------------------------------------===// // ASTWriter Implementation //===----------------------------------------------------------------------===// diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index 5b26f4eef8..8da1d8e942 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -743,6 +743,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::OMPTaskDirectiveClass: case Stmt::OMPTaskyieldDirectiveClass: case Stmt::OMPBarrierDirectiveClass: + case Stmt::OMPTaskwaitDirectiveClass: 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 3ebd9aee11..534c8a502c 100644 --- a/test/OpenMP/nesting_of_regions.cpp +++ b/test/OpenMP/nesting_of_regions.cpp @@ -56,6 +56,11 @@ void foo() { #pragma omp barrier bar(); } +#pragma omp parallel + { +#pragma omp taskwait + bar(); + } // SIMD DIRECTIVE #pragma omp simd @@ -134,6 +139,11 @@ void foo() { #pragma omp barrier // expected-error {{OpenMP constructs may not be nested inside a simd region}} bar(); } +#pragma omp simd + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait // expected-error {{OpenMP constructs may not be nested inside a simd region}} + bar(); + } // FOR DIRECTIVE #pragma omp for @@ -231,6 +241,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'for' region}} bar(); } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait + bar(); + } // SECTIONS DIRECTIVE #pragma omp sections @@ -329,6 +344,10 @@ void foo() { { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'sections' region}} } +#pragma omp sections + { +#pragma omp taskwait + } // SECTION DIRECTIVE #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} @@ -457,6 +476,14 @@ void foo() { bar(); } } +#pragma omp sections + { +#pragma omp section + { +#pragma omp taskwait + bar(); + } + } // SINGLE DIRECTIVE #pragma omp single @@ -545,6 +572,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'single' region}} bar(); } +#pragma omp single + { +#pragma omp taskwait + bar(); + } // MASTER DIRECTIVE #pragma omp master @@ -633,6 +665,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'master' region}} bar(); } +#pragma omp master + { +#pragma omp taskwait + bar(); + } // PARALLEL FOR DIRECTIVE #pragma omp parallel for @@ -730,6 +767,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'parallel for' region}} bar(); } +#pragma omp parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait + bar(); + } // PARALLEL SECTIONS DIRECTIVE #pragma omp parallel sections @@ -825,6 +867,10 @@ void foo() { { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'parallel sections' region}} } +#pragma omp parallel sections + { +#pragma omp taskwait + } // TASK DIRECTIVE #pragma omp task @@ -875,6 +921,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'task' region}} bar(); } +#pragma omp task + { +#pragma omp taskwait + bar(); + } } void foo() { @@ -932,6 +983,11 @@ void foo() { #pragma omp barrier bar(); } +#pragma omp parallel + { +#pragma omp taskwait + bar(); + } // SIMD DIRECTIVE #pragma omp simd @@ -1003,6 +1059,11 @@ void foo() { #pragma omp barrier // expected-error {{OpenMP constructs may not be nested inside a simd region}} bar(); } +#pragma omp simd + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait // expected-error {{OpenMP constructs may not be nested inside a simd region}} + bar(); + } // FOR DIRECTIVE #pragma omp for @@ -1091,6 +1152,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'for' region}} bar(); } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait + bar(); + } // SECTIONS DIRECTIVE #pragma omp sections @@ -1178,6 +1244,10 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'sections' region}} bar(); } +#pragma omp sections + { +#pragma omp taskwait + } // SECTION DIRECTIVE #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} @@ -1306,6 +1376,14 @@ void foo() { bar(); } } +#pragma omp sections + { +#pragma omp section + { +#pragma omp taskwait + bar(); + } + } // SINGLE DIRECTIVE #pragma omp single @@ -1389,6 +1467,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'single' region}} bar(); } +#pragma omp single + { +#pragma omp taskwait + bar(); + } // MASTER DIRECTIVE #pragma omp master @@ -1477,6 +1560,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'master' region}} bar(); } +#pragma omp master + { +#pragma omp taskwait + bar(); + } // PARALLEL FOR DIRECTIVE #pragma omp parallel for @@ -1573,6 +1661,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'parallel for' region}} bar(); } +#pragma omp parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait + bar(); + } // PARALLEL SECTIONS DIRECTIVE #pragma omp parallel sections @@ -1666,6 +1759,10 @@ void foo() { { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'parallel sections' region}} } +#pragma omp parallel sections + { +#pragma omp taskwait + } // TASK DIRECTIVE #pragma omp task @@ -1716,6 +1813,11 @@ void foo() { #pragma omp barrier // expected-error {{region cannot be closely nested inside 'task' region}} bar(); } +#pragma omp task + { +#pragma omp taskwait + bar(); + } return foo(); } diff --git a/test/OpenMP/taskwait_ast_print.cpp b/test/OpenMP/taskwait_ast_print.cpp new file mode 100644 index 0000000000..994262242e --- /dev/null +++ b/test/OpenMP/taskwait_ast_print.cpp @@ -0,0 +1,32 @@ +// 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 +T tmain(T argc) { + static T a; +#pragma omp taskwait + return a + argc; +} +// CHECK: static int a; +// CHECK-NEXT: #pragma omp taskwait +// CHECK: static char a; +// CHECK-NEXT: #pragma omp taskwait +// CHECK: static T a; +// CHECK-NEXT: #pragma omp taskwait + +int main(int argc, char **argv) { + static int a; +// CHECK: static int a; +#pragma omp taskwait + // CHECK-NEXT: #pragma omp taskwait + return tmain(argc) + tmain(argv[0][0]) + a; +} + +#endif diff --git a/test/OpenMP/taskwait_messages.cpp b/test/OpenMP/taskwait_messages.cpp new file mode 100644 index 0000000000..f325c73283 --- /dev/null +++ b/test/OpenMP/taskwait_messages.cpp @@ -0,0 +1,110 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 %s + +template +T tmain(T argc) { +#pragma omp taskwait + ; +#pragma omp taskwait untied // expected-error {{unexpected OpenMP clause 'untied' in directive '#pragma omp taskwait'}} +#pragma omp taskwait unknown // expected-warning {{extra tokens at the end of '#pragma omp taskwait' are ignored}} + if (argc) +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + if (argc) { +#pragma omp taskwait + } + while (argc) +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + while (argc) { +#pragma omp taskwait + } + do +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + while (argc) + ; + do { +#pragma omp taskwait + } while (argc); + switch (argc) +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + switch (argc) + case 1: +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + switch (argc) + case 1: { +#pragma omp taskwait + } + switch (argc) { +#pragma omp taskwait + case 1: +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + break; + default: { +#pragma omp taskwait + } break; + } + for (;;) +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + for (;;) { +#pragma omp taskwait + } +label: +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} +label1 : { +#pragma omp taskwait +} + + return T(); +} + +int main(int argc, char **argv) { +#pragma omp taskwait + ; +#pragma omp taskwait untied // expected-error {{unexpected OpenMP clause 'untied' in directive '#pragma omp taskwait'}} +#pragma omp taskwait unknown // expected-warning {{extra tokens at the end of '#pragma omp taskwait' are ignored}} + if (argc) +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + if (argc) { +#pragma omp taskwait + } + while (argc) +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + while (argc) { +#pragma omp taskwait + } + do +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + while (argc) + ; + do { +#pragma omp taskwait + } while (argc); + switch (argc) +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + switch (argc) + case 1: +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + switch (argc) + case 1: { +#pragma omp taskwait + } + switch (argc) { +#pragma omp taskwait + case 1: +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + break; + default: { +#pragma omp taskwait + } break; + } + for (;;) +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} + for (;;) { +#pragma omp taskwait + } +label: +#pragma omp taskwait // expected-error {{'#pragma omp taskwait' cannot be an immediate substatement}} +label1 : { +#pragma omp taskwait +} + + return tmain(argc); +} diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index fe46e3b4d1..ce74f9f9c4 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1866,6 +1866,7 @@ public: void VisitOMPTaskDirective(const OMPTaskDirective *D); void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D); void VisitOMPBarrierDirective(const OMPBarrierDirective *D); + void VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D); private: void AddDeclarationNameInfo(const Stmt *S); @@ -2352,6 +2353,10 @@ void EnqueueVisitor::VisitOMPBarrierDirective(const OMPBarrierDirective *D) { VisitOMPExecutableDirective(D); } +void EnqueueVisitor::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D) { + VisitOMPExecutableDirective(D); +} + void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) { EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S); } @@ -4048,6 +4053,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { return cxstring::createRef("OMPTaskyieldDirective"); case CXCursor_OMPBarrierDirective: return cxstring::createRef("OMPBarrierDirective"); + case CXCursor_OMPTaskwaitDirective: + return cxstring::createRef("OMPTaskwaitDirective"); } llvm_unreachable("Unhandled CXCursorKind"); diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index 634918c075..b8b949a16c 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -553,6 +553,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent, case Stmt::OMPBarrierDirectiveClass: K = CXCursor_OMPBarrierDirective; break; + case Stmt::OMPTaskwaitDirectiveClass: + K = CXCursor_OMPTaskwaitDirective; + break; } CXCursor C = { K, 0, { Parent, S, TU } };