From 3cddbb56a1edcd60378cbc5bfbd93ac8f3fac0c4 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Tue, 1 Dec 2015 04:18:41 +0000 Subject: [PATCH] [OPENMP 4.5] Parsing/sema analysis for 'taskloop' directive. Adds initial parsing and semantic analysis for 'taskloop' directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254367 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang-c/Index.h | 6 +- include/clang/AST/RecursiveASTVisitor.h | 3 + include/clang/AST/StmtOpenMP.h | 115 ++- include/clang/Basic/OpenMPKinds.def | 18 + include/clang/Basic/StmtNodes.td | 2 + include/clang/Sema/Sema.h | 6 + include/clang/Serialization/ASTBitCodes.h | 1 + lib/AST/StmtOpenMP.cpp | 48 ++ lib/AST/StmtPrinter.cpp | 6 + lib/AST/StmtProfile.cpp | 4 + lib/Basic/OpenMPKinds.cpp | 14 +- lib/CodeGen/CGStmt.cpp | 3 + lib/CodeGen/CGStmtOpenMP.cpp | 10 +- lib/CodeGen/CodeGenFunction.h | 1 + lib/Parse/ParseOpenMP.cpp | 4 +- lib/Sema/SemaOpenMP.cpp | 114 ++- lib/Sema/TreeTransform.h | 11 + lib/Serialization/ASTReaderStmt.cpp | 12 + lib/Serialization/ASTWriterStmt.cpp | 5 + lib/StaticAnalyzer/Core/ExprEngine.cpp | 1 + test/OpenMP/nesting_of_regions.cpp | 510 ++++++++++++ test/OpenMP/taskloop_ast_print.cpp | 74 ++ test/OpenMP/taskloop_collapse_messages.cpp | 83 ++ .../OpenMP/taskloop_firstprivate_messages.cpp | 313 ++++++++ test/OpenMP/taskloop_lastprivate_messages.cpp | 287 +++++++ test/OpenMP/taskloop_loop_messages.cpp | 736 ++++++++++++++++++ test/OpenMP/taskloop_misc_messages.c | 369 +++++++++ test/OpenMP/taskloop_private_messages.cpp | 195 +++++ tools/libclang/CIndex.cpp | 7 + tools/libclang/CXCursor.cpp | 3 + 30 files changed, 2927 insertions(+), 34 deletions(-) create mode 100644 test/OpenMP/taskloop_ast_print.cpp create mode 100644 test/OpenMP/taskloop_collapse_messages.cpp create mode 100644 test/OpenMP/taskloop_firstprivate_messages.cpp create mode 100644 test/OpenMP/taskloop_lastprivate_messages.cpp create mode 100644 test/OpenMP/taskloop_loop_messages.cpp create mode 100644 test/OpenMP/taskloop_misc_messages.c create mode 100644 test/OpenMP/taskloop_private_messages.cpp diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index d181dab8c3..b71647564b 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -2256,7 +2256,11 @@ enum CXCursorKind { */ CXCursor_OMPTargetDataDirective = 257, - CXCursor_LastStmt = CXCursor_OMPTargetDataDirective, + /** \brief OpenMP taskloop directive. + */ + CXCursor_OMPTaskLoopDirective = 258, + + CXCursor_LastStmt = CXCursor_OMPTaskLoopDirective, /** * \brief Cursor that represents the translation unit itself. diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 1cf3736696..9dd1d4c5d4 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2431,6 +2431,9 @@ DEF_TRAVERSE_STMT(OMPTargetDataDirective, DEF_TRAVERSE_STMT(OMPTeamsDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) +DEF_TRAVERSE_STMT(OMPTaskLoopDirective, + { 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 8f84602207..b2e226341c 100644 --- a/include/clang/AST/StmtOpenMP.h +++ b/include/clang/AST/StmtOpenMP.h @@ -391,8 +391,9 @@ protected: /// \brief Offset to the start of children expression arrays. static unsigned getArraysOffset(OpenMPDirectiveKind Kind) { - return isOpenMPWorksharingDirective(Kind) ? WorksharingEnd - : DefaultEnd; + return (isOpenMPWorksharingDirective(Kind) || Kind == OMPD_taskloop) + ? WorksharingEnd + : DefaultEnd; } /// \brief Children number. @@ -421,37 +422,44 @@ protected: void setInit(Expr *Init) { *std::next(child_begin(), InitOffset) = Init; } void setInc(Expr *Inc) { *std::next(child_begin(), IncOffset) = Inc; } void setIsLastIterVariable(Expr *IL) { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); *std::next(child_begin(), IsLastIterVariableOffset) = IL; } void setLowerBoundVariable(Expr *LB) { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); *std::next(child_begin(), LowerBoundVariableOffset) = LB; } void setUpperBoundVariable(Expr *UB) { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); *std::next(child_begin(), UpperBoundVariableOffset) = UB; } void setStrideVariable(Expr *ST) { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); *std::next(child_begin(), StrideVariableOffset) = ST; } void setEnsureUpperBound(Expr *EUB) { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); *std::next(child_begin(), EnsureUpperBoundOffset) = EUB; } void setNextLowerBound(Expr *NLB) { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); *std::next(child_begin(), NextLowerBoundOffset) = NLB; } void setNextUpperBound(Expr *NUB) { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); *std::next(child_begin(), NextUpperBoundOffset) = NUB; } @@ -578,43 +586,50 @@ public: reinterpret_cast(*std::next(child_begin(), IncOffset))); } Expr *getIsLastIterVariable() const { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); return const_cast(reinterpret_cast( *std::next(child_begin(), IsLastIterVariableOffset))); } Expr *getLowerBoundVariable() const { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); return const_cast(reinterpret_cast( *std::next(child_begin(), LowerBoundVariableOffset))); } Expr *getUpperBoundVariable() const { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); return const_cast(reinterpret_cast( *std::next(child_begin(), UpperBoundVariableOffset))); } Expr *getStrideVariable() const { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); return const_cast(reinterpret_cast( *std::next(child_begin(), StrideVariableOffset))); } Expr *getEnsureUpperBound() const { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); return const_cast(reinterpret_cast( *std::next(child_begin(), EnsureUpperBoundOffset))); } Expr *getNextLowerBound() const { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); return const_cast(reinterpret_cast( *std::next(child_begin(), NextLowerBoundOffset))); } Expr *getNextUpperBound() const { - assert(isOpenMPWorksharingDirective(getDirectiveKind()) && + assert((isOpenMPWorksharingDirective(getDirectiveKind()) || + getDirectiveKind() == OMPD_taskloop) && "expected worksharing loop directive"); return const_cast(reinterpret_cast( *std::next(child_begin(), NextUpperBoundOffset))); @@ -665,7 +680,8 @@ public: T->getStmtClass() == OMPForDirectiveClass || T->getStmtClass() == OMPForSimdDirectiveClass || T->getStmtClass() == OMPParallelForDirectiveClass || - T->getStmtClass() == OMPParallelForSimdDirectiveClass; + T->getStmtClass() == OMPParallelForSimdDirectiveClass || + T->getStmtClass() == OMPTaskLoopDirectiveClass; } }; @@ -2183,6 +2199,71 @@ public: } }; +/// \brief This represents '#pragma omp taskloop' directive. +/// +/// \code +/// #pragma omp taskloop private(a,b) grainsize(val) num_tasks(num) +/// \endcode +/// In this example directive '#pragma omp taskloop' has clauses 'private' +/// with the variables 'a' and 'b', 'grainsize' with expression 'val' and +/// 'num_tasks' with expression 'num'. +/// +class OMPTaskLoopDirective : public OMPLoopDirective { + 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 CollapsedNum Number of collapsed nested loops. + /// \param NumClauses Number of clauses. + /// + OMPTaskLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc, + unsigned CollapsedNum, unsigned NumClauses) + : OMPLoopDirective(this, OMPTaskLoopDirectiveClass, OMPD_taskloop, + StartLoc, EndLoc, CollapsedNum, NumClauses) {} + + /// \brief Build an empty directive. + /// + /// \param CollapsedNum Number of collapsed nested loops. + /// \param NumClauses Number of clauses. + /// + explicit OMPTaskLoopDirective(unsigned CollapsedNum, unsigned NumClauses) + : OMPLoopDirective(this, OMPTaskLoopDirectiveClass, OMPD_taskloop, + SourceLocation(), SourceLocation(), CollapsedNum, + NumClauses) {} + +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 CollapsedNum Number of collapsed loops. + /// \param Clauses List of clauses. + /// \param AssociatedStmt Statement, associated with the directive. + /// \param Exprs Helper expressions for CodeGen. + /// + static OMPTaskLoopDirective * + Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, + unsigned CollapsedNum, ArrayRef Clauses, + Stmt *AssociatedStmt, const HelperExprs &Exprs); + + /// \brief Creates an empty directive with the place + /// for \a NumClauses clauses. + /// + /// \param C AST context. + /// \param CollapsedNum Number of collapsed nested loops. + /// \param NumClauses Number of clauses. + /// + static OMPTaskLoopDirective *CreateEmpty(const ASTContext &C, + unsigned NumClauses, + unsigned CollapsedNum, EmptyShell); + + static bool classof(const Stmt *T) { + return T->getStmtClass() == OMPTaskLoopDirectiveClass; + } +}; + } // end namespace clang #endif diff --git a/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def index 418a0da37d..63d2d2eb7e 100644 --- a/include/clang/Basic/OpenMPKinds.def +++ b/include/clang/Basic/OpenMPKinds.def @@ -69,6 +69,9 @@ #ifndef OPENMP_ORDERED_CLAUSE # define OPENMP_ORDERED_CLAUSE(Name) #endif +#ifndef OPENMP_TASKLOOP_CLAUSE +# define OPENMP_TASKLOOP_CLAUSE(Name) +#endif #ifndef OPENMP_DEFAULT_KIND # define OPENMP_DEFAULT_KIND(Name) #endif @@ -115,6 +118,7 @@ OPENMP_DIRECTIVE_EXT(parallel_for_simd, "parallel for simd") OPENMP_DIRECTIVE_EXT(parallel_sections, "parallel sections") OPENMP_DIRECTIVE_EXT(for_simd, "for simd") OPENMP_DIRECTIVE_EXT(cancellation_point, "cancellation point") +OPENMP_DIRECTIVE(taskloop) // OpenMP clauses. OPENMP_CLAUSE(if, OMPIfClause) @@ -340,6 +344,20 @@ OPENMP_MAP_KIND(delete) OPENMP_MAP_KIND(release) OPENMP_MAP_KIND(always) +// Clauses allowed for OpenMP directive 'taskloop'. +// TODO: add next clauses +OPENMP_TASKLOOP_CLAUSE(if) +OPENMP_TASKLOOP_CLAUSE(shared) +OPENMP_TASKLOOP_CLAUSE(private) +OPENMP_TASKLOOP_CLAUSE(firstprivate) +OPENMP_TASKLOOP_CLAUSE(lastprivate) +OPENMP_TASKLOOP_CLAUSE(default) +OPENMP_TASKLOOP_CLAUSE(collapse) +OPENMP_TASKLOOP_CLAUSE(final) +OPENMP_TASKLOOP_CLAUSE(untied) +OPENMP_TASKLOOP_CLAUSE(mergeable) + +#undef OPENMP_TASKLOOP_CLAUSE #undef OPENMP_LINEAR_KIND #undef OPENMP_DEPEND_KIND #undef OPENMP_SCHEDULE_KIND diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td index e3192efc56..83e7213ff7 100644 --- a/include/clang/Basic/StmtNodes.td +++ b/include/clang/Basic/StmtNodes.td @@ -219,3 +219,5 @@ def OMPTargetDataDirective : DStmt; def OMPTeamsDirective : DStmt; def OMPCancellationPointDirective : DStmt; def OMPCancelDirective : DStmt; +def OMPTaskLoopDirective : DStmt; + diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 3256fba0c8..2cdbf04192 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -7934,6 +7934,12 @@ public: SourceLocation StartLoc, SourceLocation EndLoc, OpenMPDirectiveKind CancelRegion); + /// \brief Called on well-formed '\#pragma omp taskloop' after parsing of the + /// associated statement. + StmtResult ActOnOpenMPTaskLoopDirective( + ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc, + llvm::DenseMap &VarsWithImplicitDSA); OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index a7556b7ced..d61cb38956 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -1447,6 +1447,7 @@ namespace clang { STMT_OMP_TASKGROUP_DIRECTIVE, STMT_OMP_CANCELLATION_POINT_DIRECTIVE, STMT_OMP_CANCEL_DIRECTIVE, + STMT_OMP_TASKLOOP_DIRECTIVE, EXPR_OMP_ARRAY_SECTION, // ARC diff --git a/lib/AST/StmtOpenMP.cpp b/lib/AST/StmtOpenMP.cpp index ead92b2b35..4099b55859 100644 --- a/lib/AST/StmtOpenMP.cpp +++ b/lib/AST/StmtOpenMP.cpp @@ -738,3 +738,51 @@ OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C, C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); return new (Mem) OMPTeamsDirective(NumClauses); } + +OMPTaskLoopDirective *OMPTaskLoopDirective::Create( + const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, + unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, + const HelperExprs &Exprs) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskLoopDirective), + llvm::alignOf()); + void *Mem = + C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_taskloop)); + OMPTaskLoopDirective *Dir = new (Mem) + OMPTaskLoopDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); + Dir->setClauses(Clauses); + Dir->setAssociatedStmt(AssociatedStmt); + Dir->setIterationVariable(Exprs.IterationVarRef); + Dir->setLastIteration(Exprs.LastIteration); + Dir->setCalcLastIteration(Exprs.CalcLastIteration); + Dir->setPreCond(Exprs.PreCond); + Dir->setCond(Exprs.Cond); + Dir->setInit(Exprs.Init); + Dir->setInc(Exprs.Inc); + Dir->setIsLastIterVariable(Exprs.IL); + Dir->setLowerBoundVariable(Exprs.LB); + Dir->setUpperBoundVariable(Exprs.UB); + Dir->setStrideVariable(Exprs.ST); + Dir->setEnsureUpperBound(Exprs.EUB); + Dir->setNextLowerBound(Exprs.NLB); + Dir->setNextUpperBound(Exprs.NUB); + Dir->setCounters(Exprs.Counters); + Dir->setPrivateCounters(Exprs.PrivateCounters); + Dir->setInits(Exprs.Inits); + Dir->setUpdates(Exprs.Updates); + Dir->setFinals(Exprs.Finals); + return Dir; +} + +OMPTaskLoopDirective *OMPTaskLoopDirective::CreateEmpty(const ASTContext &C, + unsigned NumClauses, + unsigned CollapsedNum, + EmptyShell) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskLoopDirective), + llvm::alignOf()); + void *Mem = + C.Allocate(Size + sizeof(OMPClause *) * NumClauses + + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_taskloop)); + return new (Mem) OMPTaskLoopDirective(CollapsedNum, NumClauses); +} + diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 8e8ef2297c..20cf32a8cf 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1029,6 +1029,12 @@ void StmtPrinter::VisitOMPCancelDirective(OMPCancelDirective *Node) { << getOpenMPDirectiveName(Node->getCancelRegion()) << " "; PrintOMPExecutableDirective(Node); } + +void StmtPrinter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *Node) { + Indent() << "#pragma omp taskloop "; + PrintOMPExecutableDirective(Node); +} + //===----------------------------------------------------------------------===// // Expr printing methods. //===----------------------------------------------------------------------===// diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 511303a515..3b195aae6c 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -582,6 +582,10 @@ void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) { VisitOMPExecutableDirective(S); } +void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) { + VisitOMPLoopDirective(S); +} + void StmtProfiler::VisitExpr(const Expr *S) { VisitStmt(S); } diff --git a/lib/Basic/OpenMPKinds.cpp b/lib/Basic/OpenMPKinds.cpp index 13cd1b928d..f6bed5412a 100644 --- a/lib/Basic/OpenMPKinds.cpp +++ b/lib/Basic/OpenMPKinds.cpp @@ -405,6 +405,16 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, #define OPENMP_ORDERED_CLAUSE(Name) \ case OMPC_##Name: \ return true; +#include "clang/Basic/OpenMPKinds.def" + default: + break; + } + break; + case OMPD_taskloop: + switch (CKind) { +#define OPENMP_TASKLOOP_CLAUSE(Name) \ + case OMPC_##Name: \ + return true; #include "clang/Basic/OpenMPKinds.def" default: break; @@ -427,8 +437,8 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) { return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd || - DKind == OMPD_parallel_for || - DKind == OMPD_parallel_for_simd; // TODO add next directives. + DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd || + DKind == OMPD_taskloop; // TODO add next directives. } bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) { diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 7c4fb4137a..19c1ceea18 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -256,6 +256,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::OMPTargetDataDirectiveClass: EmitOMPTargetDataDirective(cast(*S)); break; + case Stmt::OMPTaskLoopDirectiveClass: + EmitOMPTaskLoopDirective(cast(*S)); + break; } } diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index dd9401b91d..567c03617c 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -2542,10 +2542,18 @@ CodeGenFunction::getOMPCancelDestination(OpenMPDirectiveKind Kind) { // Generate the instructions for '#pragma omp target data' directive. void CodeGenFunction::EmitOMPTargetDataDirective( const OMPTargetDataDirective &S) { - // emit the code inside the construct for now auto CS = cast(S.getAssociatedStmt()); CGM.getOpenMPRuntime().emitInlinedDirective( *this, OMPD_target_data, [&CS](CodeGenFunction &CGF) { CGF.EmitStmt(CS->getCapturedStmt()); }); } + +void CodeGenFunction::EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S) { + // emit the code inside the construct for now + auto CS = cast(S.getAssociatedStmt()); + CGM.getOpenMPRuntime().emitInlinedDirective( + *this, OMPD_taskloop, + [&CS](CodeGenFunction &CGF) { CGF.EmitStmt(CS->getCapturedStmt()); }); +} + diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 8a19d5563a..18ccd4148d 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -2334,6 +2334,7 @@ public: void EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S); void EmitOMPCancelDirective(const OMPCancelDirective &S); + void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S); /// \brief Emit inner loop of the worksharing/simd construct. /// diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index cf10801112..22b1d08e69 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -137,6 +137,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { case OMPD_cancellation_point: case OMPD_cancel: case OMPD_target_data: + case OMPD_taskloop: Diag(Tok, diag::err_omp_unexpected_directive) << getOpenMPDirectiveName(DKind); break; @@ -232,7 +233,8 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) { case OMPD_target: case OMPD_teams: case OMPD_taskgroup: - case OMPD_target_data: { + case OMPD_target_data: + case OMPD_taskloop: { 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 e6f3eb6c85..ef293babb9 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -343,7 +343,8 @@ public: }; bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || - isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; + isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || + DKind == OMPD_taskloop; } } // namespace @@ -1454,6 +1455,14 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { Params); break; } + case OMPD_taskloop: { + Sema::CapturedParamNameType Params[] = { + std::make_pair(StringRef(), QualType()) // __context with shared vars + }; + ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, + Params); + break; + } case OMPD_threadprivate: case OMPD_taskyield: case OMPD_barrier: @@ -1536,6 +1545,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel | cancellation | | // | | point | ! | // | parallel | cancel | ! | + // | parallel | taskloop | * | // +------------------+-----------------+------------------------------------+ // | for | parallel | * | // | for | for | + | @@ -1562,6 +1572,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for | cancellation | | // | | point | ! | // | for | cancel | ! | + // | for | taskloop | * | // +------------------+-----------------+------------------------------------+ // | master | parallel | * | // | master | for | + | @@ -1588,6 +1599,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | master | cancellation | | // | | point | | // | master | cancel | | + // | master | taskloop | * | // +------------------+-----------------+------------------------------------+ // | critical | parallel | * | // | critical | for | + | @@ -1613,6 +1625,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | critical | cancellation | | // | | point | | // | critical | cancel | | + // | critical | taskloop | * | // +------------------+-----------------+------------------------------------+ // | simd | parallel | | // | simd | for | | @@ -1639,6 +1652,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | simd | cancellation | | // | | point | | // | simd | cancel | | + // | simd | taskloop | | // +------------------+-----------------+------------------------------------+ // | for simd | parallel | | // | for simd | for | | @@ -1665,6 +1679,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for simd | cancellation | | // | | point | | // | for simd | cancel | | + // | for simd | taskloop | | // +------------------+-----------------+------------------------------------+ // | parallel for simd| parallel | | // | parallel for simd| for | | @@ -1691,6 +1706,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for simd| cancellation | | // | | point | | // | parallel for simd| cancel | | + // | parallel for simd| taskloop | | // +------------------+-----------------+------------------------------------+ // | sections | parallel | * | // | sections | for | + | @@ -1717,6 +1733,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | sections | cancellation | | // | | point | ! | // | sections | cancel | ! | + // | sections | taskloop | * | // +------------------+-----------------+------------------------------------+ // | section | parallel | * | // | section | for | + | @@ -1743,6 +1760,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | section | cancellation | | // | | point | ! | // | section | cancel | ! | + // | section | taskloop | * | // +------------------+-----------------+------------------------------------+ // | single | parallel | * | // | single | for | + | @@ -1769,6 +1787,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | single | cancellation | | // | | point | | // | single | cancel | | + // | single | taskloop | * | // +------------------+-----------------+------------------------------------+ // | parallel for | parallel | * | // | parallel for | for | + | @@ -1795,6 +1814,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for | cancellation | | // | | point | ! | // | parallel for | cancel | ! | + // | parallel for | taskloop | * | // +------------------+-----------------+------------------------------------+ // | parallel sections| parallel | * | // | parallel sections| for | + | @@ -1821,6 +1841,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel sections| cancellation | | // | | point | ! | // | parallel sections| cancel | ! | + // | parallel sections| taskloop | * | // +------------------+-----------------+------------------------------------+ // | task | parallel | * | // | task | for | + | @@ -1847,6 +1868,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | task | cancellation | | // | | point | ! | // | task | cancel | ! | + // | task | taskloop | * | // +------------------+-----------------+------------------------------------+ // | ordered | parallel | * | // | ordered | for | + | @@ -1873,6 +1895,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | ordered | cancellation | | // | | point | | // | ordered | cancel | | + // | ordered | taskloop | * | // +------------------+-----------------+------------------------------------+ // | atomic | parallel | | // | atomic | for | | @@ -1899,6 +1922,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | atomic | cancellation | | // | | point | | // | atomic | cancel | | + // | atomic | taskloop | | // +------------------+-----------------+------------------------------------+ // | target | parallel | * | // | target | for | * | @@ -1925,6 +1949,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | target | cancellation | | // | | point | | // | target | cancel | | + // | target | taskloop | * | // +------------------+-----------------+------------------------------------+ // | teams | parallel | * | // | teams | for | + | @@ -1951,6 +1976,34 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | teams | cancellation | | // | | point | | // | teams | cancel | | + // | teams | taskloop | + | + // +------------------+-----------------+------------------------------------+ + // | taskloop | parallel | * | + // | taskloop | for | + | + // | taskloop | for simd | + | + // | taskloop | master | + | + // | taskloop | critical | * | + // | taskloop | simd | * | + // | taskloop | sections | + | + // | taskloop | section | + | + // | taskloop | single | + | + // | taskloop | parallel for | * | + // | taskloop |parallel for simd| * | + // | taskloop |parallel sections| * | + // | taskloop | task | * | + // | taskloop | taskyield | * | + // | taskloop | barrier | + | + // | taskloop | taskwait | * | + // | taskloop | taskgroup | * | + // | taskloop | flush | * | + // | taskloop | ordered | + | + // | taskloop | atomic | * | + // | taskloop | target | * | + // | taskloop | teams | + | + // | taskloop | cancellation | | + // | | point | | + // | taskloop | cancel | | + // | taskloop | taskloop | * | // +------------------+-----------------+------------------------------------+ if (Stack->getCurScope()) { auto ParentRegion = Stack->getParentDirective(); @@ -2021,7 +2074,8 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // A master region may not be closely nested inside a worksharing, // atomic, or explicit task region. NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || - ParentRegion == OMPD_task; + ParentRegion == OMPD_task || + ParentRegion == OMPD_taskloop; } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { // OpenMP [2.16, Nesting of Regions] // A critical region may not be nested (closely or otherwise) inside a @@ -2058,7 +2112,8 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || ParentRegion == OMPD_task || ParentRegion == OMPD_master || - ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; + ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || + ParentRegion == OMPD_taskloop; } else if (isOpenMPWorksharingDirective(CurrentRegion) && !isOpenMPParallelDirective(CurrentRegion)) { // OpenMP [2.16, Nesting of Regions] @@ -2067,7 +2122,8 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || ParentRegion == OMPD_task || ParentRegion == OMPD_master || - ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; + ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || + ParentRegion == OMPD_taskloop; Recommend = ShouldBeInParallelRegion; } else if (CurrentRegion == OMPD_ordered) { // OpenMP [2.16, Nesting of Regions] @@ -2080,6 +2136,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // that can appear in the simd region. NestingProhibited = ParentRegion == OMPD_critical || ParentRegion == OMPD_task || + ParentRegion == OMPD_taskloop || !(isOpenMPSimdDirective(ParentRegion) || Stack->isParentOrderedRegion()); Recommend = ShouldBeInOrderedRegion; @@ -2357,6 +2414,11 @@ StmtResult Sema::ActOnOpenMPExecutableDirective( EndLoc); AllowedNameModifiers.push_back(OMPD_target_data); break; + case OMPD_taskloop: + Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, + EndLoc, VarsWithInheritedDSA); + AllowedNameModifiers.push_back(OMPD_taskloop); + break; case OMPD_threadprivate: llvm_unreachable("OpenMP Directive is not allowed"); case OMPD_unknown: @@ -3185,9 +3247,10 @@ static bool CheckOpenMPIterationSpace( : OMPC_private; if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || - (isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) && - DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && - DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_threadprivate)) && + ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) && + !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && + DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate && + DVar.CKind != OMPC_threadprivate)) && ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || DVar.RefExpr != nullptr)) { SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) @@ -3222,7 +3285,8 @@ static bool CheckOpenMPIterationSpace( // Build the loop's iteration space representation. ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); ResultIterSpace.NumIterations = ISC.BuildNumIterations( - DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind)); + DSA.getCurScope(), + (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop)); ResultIterSpace.CounterVar = ISC.BuildCounterVar(); ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); ResultIterSpace.CounterInit = ISC.BuildCounterInit(); @@ -3530,7 +3594,7 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, QualType VType = LastIteration.get()->getType(); // Build variables passed into runtime, nesessary for worksharing directives. ExprResult LB, UB, IL, ST, EUB; - if (isOpenMPWorksharingDirective(DKind)) { + if ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop)) { // Lower bound variable, initialized with zero. VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); @@ -3578,7 +3642,7 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, { VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); - Expr *RHS = isOpenMPWorksharingDirective(DKind) + Expr *RHS = (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) ? LB.get() : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); @@ -3588,7 +3652,7 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. SourceLocation CondLoc; ExprResult Cond = - isOpenMPWorksharingDirective(DKind) + (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), NumIterations.get()); @@ -3608,7 +3672,7 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). // Used for directives with static scheduling. ExprResult NextLB, NextUB; - if (isOpenMPWorksharingDirective(DKind)) { + if (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) { // LB + ST NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); if (!NextLB.isUsable()) @@ -5067,6 +5131,32 @@ StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef Clauses, CancelRegion); } +StmtResult Sema::ActOnOpenMPTaskLoopDirective( + ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc, + llvm::DenseMap &VarsWithImplicitDSA) { + if (!AStmt) + return StmtError(); + + assert(isa(AStmt) && "Captured statement expected"); + OMPLoopDirective::HelperExprs B; + // In presence of clause 'collapse' or 'ordered' with number of loops, it will + // define the nested loops number. + unsigned NestedLoopCount = + CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), + getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, + VarsWithImplicitDSA, B); + if (NestedLoopCount == 0) + return StmtError(); + + assert((CurContext->isDependentContext() || B.builtAll()) && + "omp for loop exprs were not built"); + + getCurFunction()->setHasBranchProtectedScope(); + return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, + NestedLoopCount, Clauses, AStmt, B); +} + OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, SourceLocation StartLoc, SourceLocation LParenLoc, diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index f839c90da8..589f5114cd 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -7342,6 +7342,17 @@ TreeTransform::TransformOMPCancelDirective(OMPCancelDirective *D) { return Res; } +template +StmtResult +TreeTransform::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, 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 49f06f2315..4c86219c00 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -2412,6 +2412,10 @@ void ASTStmtReader::VisitOMPCancelDirective(OMPCancelDirective *D) { D->setCancelRegion(static_cast(Record[Idx++])); } +void ASTStmtReader::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) { + VisitOMPLoopDirective(D); +} + //===----------------------------------------------------------------------===// // ASTReader Implementation //===----------------------------------------------------------------------===// @@ -3034,6 +3038,14 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { Context, Record[ASTStmtReader::NumStmtFields], Empty); break; + case STMT_OMP_TASKLOOP_DIRECTIVE: { + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + S = OMPTaskLoopDirective::CreateEmpty(Context, NumClauses, CollapsedNum, + 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 acb3a7f2cc..3cf7b18a57 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -2239,6 +2239,11 @@ void ASTStmtWriter::VisitOMPCancelDirective(OMPCancelDirective *D) { Code = serialization::STMT_OMP_CANCEL_DIRECTIVE; } +void ASTStmtWriter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) { + VisitOMPLoopDirective(D); + Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE; +} + //===----------------------------------------------------------------------===// // ASTWriter Implementation //===----------------------------------------------------------------------===// diff --git a/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp index 32f055b8c4..98e7c3b01a 100644 --- a/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -829,6 +829,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::OMPTeamsDirectiveClass: case Stmt::OMPCancellationPointDirectiveClass: case Stmt::OMPCancelDirectiveClass: + case Stmt::OMPTaskLoopDirectiveClass: 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 8a3bacf0f1..b8d5a0560f 100644 --- a/test/OpenMP/nesting_of_regions.cpp +++ b/test/OpenMP/nesting_of_regions.cpp @@ -100,6 +100,12 @@ void foo() { #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; } +#pragma omp parallel + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // SIMD DIRECTIVE #pragma omp simd @@ -227,6 +233,12 @@ void foo() { #pragma omp teams // 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 taskloop // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int i = 0; i < 10; ++i) + ++a; + } // FOR DIRECTIVE #pragma omp for @@ -377,6 +389,12 @@ void foo() { #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; } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // FOR SIMD DIRECTIVE #pragma omp for simd @@ -504,6 +522,12 @@ void foo() { #pragma omp teams // 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 taskloop // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int i = 0; i < 10; ++i) + ++a; + } // SECTIONS DIRECTIVE #pragma omp sections @@ -661,6 +685,12 @@ void foo() { #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; } +#pragma omp sections + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // SECTION DIRECTIVE #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} @@ -854,6 +884,13 @@ void foo() { #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; } +#pragma omp sections + { +#pragma omp section +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // SINGLE DIRECTIVE #pragma omp single @@ -994,6 +1031,12 @@ void foo() { #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; } +#pragma omp single + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // MASTER DIRECTIVE #pragma omp master @@ -1134,6 +1177,12 @@ void foo() { #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; } +#pragma omp master + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // CRITICAL DIRECTIVE #pragma omp critical @@ -1288,6 +1337,12 @@ void foo() { #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; } +#pragma omp critical + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // PARALLEL FOR DIRECTIVE #pragma omp parallel for @@ -1443,6 +1498,12 @@ void foo() { #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; } +#pragma omp parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // PARALLEL FOR SIMD DIRECTIVE #pragma omp parallel for simd @@ -1598,6 +1659,12 @@ void foo() { #pragma omp teams // 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 taskloop // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int i = 0; i < 10; ++i) + ++a; + } // PARALLEL SECTIONS DIRECTIVE #pragma omp parallel sections @@ -1744,6 +1811,12 @@ void foo() { #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; } +#pragma omp parallel sections + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // TASK DIRECTIVE #pragma omp task @@ -1836,6 +1909,12 @@ void foo() { #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; } +#pragma omp task + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // ORDERED DIRECTIVE #pragma omp ordered @@ -1976,6 +2055,12 @@ void foo() { #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; } +#pragma omp ordered + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // ATOMIC DIRECTIVE #pragma omp atomic @@ -2145,6 +2230,14 @@ void foo() { #pragma omp teams // expected-error {{OpenMP constructs may not be nested inside an atomic region}} ++a; } +#pragma omp atomic + // expected-error@+2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}} + // expected-note@+1 {{expected an expression statement}} + { +#pragma omp taskloop // expected-error {{OpenMP constructs may not be nested inside an atomic region}} + for (int i = 0; i < 10; ++i) + ++a; + } // TARGET DIRECTIVE #pragma omp target @@ -2250,6 +2343,12 @@ void foo() { #pragma omp teams // expected-note {{nested teams construct here}} ++a; } +#pragma omp target + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // TEAMS DIRECTIVE #pragma omp target @@ -2370,6 +2469,164 @@ void foo() { #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; } +#pragma omp target +#pragma omp teams + { +#pragma omp taskloop // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp taskloop' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ++a; + } + +// TASKLOOP DIRECTIVE +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp for // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp for simd // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp for simd' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp sections // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a taskloop region}} + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp single // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + { + bar(); + } + } + +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp master // expected-error {{region cannot be closely nested inside 'taskloop' region}} + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp critical + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel + { +#pragma omp single // OK + { + bar(); + } +#pragma omp for // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp sections // OK + { + bar(); + } + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel for + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel sections + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp task + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp taskyield + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp barrier // expected-error {{region cannot be closely nested inside 'taskloop' region}} + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp flush + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp ordered // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp atomic + ++a; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp target + ++a; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } } void foo() { @@ -2469,6 +2726,12 @@ void foo() { #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; } +#pragma omp parallel + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // SIMD DIRECTIVE #pragma omp simd @@ -2589,6 +2852,12 @@ void foo() { #pragma omp teams // 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 taskloop // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int i = 0; i < 10; ++i) + ++a; + } // FOR DIRECTIVE #pragma omp for @@ -2729,6 +2998,12 @@ void foo() { #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; } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // FOR SIMD DIRECTIVE #pragma omp for simd @@ -2849,6 +3124,12 @@ void foo() { #pragma omp teams // 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 taskloop // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int i = 0; i < 10; ++i) + ++a; + } // SECTIONS DIRECTIVE #pragma omp sections @@ -2981,6 +3262,12 @@ void foo() { #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; } +#pragma omp sections + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // SECTION DIRECTIVE #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} @@ -3180,6 +3467,15 @@ void foo() { ++a; } } +#pragma omp sections + { +#pragma omp section + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } + } // SINGLE DIRECTIVE #pragma omp single @@ -3310,6 +3606,12 @@ void foo() { #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; } +#pragma omp single + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // MASTER DIRECTIVE #pragma omp master @@ -3450,6 +3752,12 @@ void foo() { #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; } +#pragma omp master + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // CRITICAL DIRECTIVE #pragma omp critical @@ -3609,6 +3917,12 @@ void foo() { #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; } +#pragma omp critical + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // PARALLEL FOR DIRECTIVE #pragma omp parallel for @@ -3764,6 +4078,12 @@ void foo() { #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; } +#pragma omp parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // PARALLEL FOR SIMD DIRECTIVE #pragma omp parallel for simd @@ -3919,6 +4239,12 @@ void foo() { #pragma omp teams // 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 taskloop // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int i = 0; i < 10; ++i) + ++a; + } // PARALLEL SECTIONS DIRECTIVE #pragma omp parallel sections @@ -4061,6 +4387,12 @@ void foo() { #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; } +#pragma omp parallel sections + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // TASK DIRECTIVE #pragma omp task @@ -4152,6 +4484,12 @@ void foo() { #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; } +#pragma omp task + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // ATOMIC DIRECTIVE #pragma omp atomic @@ -4321,6 +4659,14 @@ void foo() { #pragma omp teams // expected-error {{OpenMP constructs may not be nested inside an atomic region}} ++a; } +#pragma omp atomic + // expected-error@+2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}} + // expected-note@+1 {{expected an expression statement}} + { +#pragma omp taskloop // expected-error {{OpenMP constructs may not be nested inside an atomic region}} + for (int i = 0; i < 10; ++i) + ++a; + } // TARGET DIRECTIVE #pragma omp target @@ -4426,6 +4772,12 @@ void foo() { #pragma omp teams // expected-note {{nested teams construct here}} ++a; } +#pragma omp target + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } // TEAMS DIRECTIVE #pragma omp target @@ -4546,6 +4898,164 @@ void foo() { #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; } +#pragma omp target +#pragma omp teams + { +#pragma omp taskloop // expected-error {{region cannot be closely nested inside 'teams' region; perhaps you forget to enclose 'omp taskloop' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ++a; + } + +// TASKLOOP DIRECTIVE +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp for // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp for simd // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp for simd' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp sections // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a taskloop region}} + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp single // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + { + bar(); + } + } + +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp master // expected-error {{region cannot be closely nested inside 'taskloop' region}} + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp critical + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel + { +#pragma omp single // OK + { + bar(); + } +#pragma omp for // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp sections // OK + { + bar(); + } + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel for + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp parallel sections + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp task + { + bar(); + } + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp taskyield + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp barrier // expected-error {{region cannot be closely nested inside 'taskloop' region}} + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp flush + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp ordered // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + bar(); + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp atomic + ++a; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp target + ++a; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'taskloop' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } return foo(); } diff --git a/test/OpenMP/taskloop_ast_print.cpp b/test/OpenMP/taskloop_ast_print.cpp new file mode 100644 index 0000000000..47e57be507 --- /dev/null +++ b/test/OpenMP/taskloop_ast_print.cpp @@ -0,0 +1,74 @@ +// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s +// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp -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) { + T b = argc, c, d, e, f, g; + static T a; +// CHECK: static T a; +#pragma omp taskloop if(taskloop: argc > N) default(shared) untied + // CHECK-NEXT: #pragma omp taskloop if(taskloop: argc > N) default(shared) untied + for (int i = 0; i < 2; ++i) + a = 2; +// CHECK-NEXT: for (int i = 0; i < 2; ++i) +// CHECK-NEXT: a = 2; +#pragma omp parallel +#pragma omp taskloop private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) shared(g) if (c) final(d) mergeable + for (int i = 0; i < 2; ++i) + for (int j = 0; j < 2; ++j) + for (int j = 0; j < 2; ++j) + for (int j = 0; j < 2; ++j) + for (int j = 0; j < 2; ++j) + for (int i = 0; i < 2; ++i) + for (int j = 0; j < 2; ++j) + for (int j = 0; j < 2; ++j) + for (int j = 0; j < 2; ++j) + for (int j = 0; j < 2; ++j) + foo(); + // CHECK-NEXT: #pragma omp parallel + // CHECK-NEXT: #pragma omp taskloop private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) shared(g) if(c) final(d) mergeable + // CHECK-NEXT: for (int i = 0; i < 2; ++i) + // CHECK-NEXT: for (int j = 0; j < 2; ++j) + // CHECK-NEXT: for (int j = 0; j < 2; ++j) + // CHECK-NEXT: for (int j = 0; j < 2; ++j) + // CHECK-NEXT: for (int j = 0; j < 2; ++j) + // CHECK-NEXT: for (int i = 0; i < 2; ++i) + // CHECK-NEXT: for (int j = 0; j < 2; ++j) + // CHECK-NEXT: for (int j = 0; j < 2; ++j) + // CHECK-NEXT: for (int j = 0; j < 2; ++j) + // CHECK-NEXT: for (int j = 0; j < 2; ++j) + // CHECK-NEXT: foo(); + return T(); +} + +int main(int argc, char **argv) { + int b = argc, c, d, e, f, g; + static int a; +// CHECK: static int a; +#pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) + // CHECK-NEXT: #pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) + for (int i = 0; i < 2; ++i) + a = 2; +// CHECK-NEXT: for (int i = 0; i < 2; ++i) +// CHECK-NEXT: a = 2; +#pragma omp parallel +#pragma omp taskloop private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) shared(g) if(argc) mergeable + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) + foo(); + // CHECK-NEXT: #pragma omp parallel + // CHECK-NEXT: #pragma omp taskloop private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) shared(g) if(argc) mergeable + // CHECK-NEXT: for (int i = 0; i < 10; ++i) + // CHECK-NEXT: for (int j = 0; j < 10; ++j) + // CHECK-NEXT: foo(); + return (tmain(argc) + tmain(argv[0][0])); +} + +#endif diff --git a/test/OpenMP/taskloop_collapse_messages.cpp b/test/OpenMP/taskloop_collapse_messages.cpp new file mode 100644 index 0000000000..65b1e2dfa3 --- /dev/null +++ b/test/OpenMP/taskloop_collapse_messages.cpp @@ -0,0 +1,83 @@ +// RUN: %clang_cc1 -verify -fopenmp %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} + +template // expected-note {{declared here}} +T tmain(T argc, S **argv) { //expected-note 2 {{declared here}} + #pragma omp taskloop collapse // expected-error {{expected '(' after 'collapse'}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp taskloop collapse ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp taskloop collapse () // expected-error {{expected expression}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + // expected-error@+3 {{expected ')'}} expected-note@+3 {{to match this '('}} + // expected-error@+2 2 {{expression is not an integral constant expression}} + // expected-note@+1 2 {{read of non-const variable 'argc' is not allowed in a constant expression}} + #pragma omp taskloop collapse (argc + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + // expected-error@+1 2 {{argument to 'collapse' clause must be a positive integer value}} + #pragma omp taskloop collapse (ST // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp taskloop collapse (1)) // expected-warning {{extra tokens at the end of '#pragma omp taskloop' are ignored}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp taskloop collapse ((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'collapse' clause}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp taskloop', but found only 1}} + // expected-error@+3 2 {{directive '#pragma omp taskloop' cannot contain more than one 'collapse' clause}} + // expected-error@+2 2 {{argument to 'collapse' clause must be a positive integer value}} + // expected-error@+1 2 {{expression is not an integral constant expression}} + #pragma omp taskloop collapse (foobool(argc)), collapse (true), collapse (-5) + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp taskloop collapse (S) // expected-error {{'S' does not refer to a value}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + // expected-error@+1 2 {{expression is not an integral constant expression}} + #pragma omp taskloop collapse (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp taskloop collapse (1) + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp taskloop collapse (N) // expected-error {{argument to 'collapse' clause must be a positive integer value}} + for (T i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp taskloop collapse (2) // expected-note {{as specified in 'collapse' clause}} + foo(); // expected-error {{expected 2 for loops after '#pragma omp taskloop'}} + return argc; +} + +int main(int argc, char **argv) { + #pragma omp taskloop collapse // expected-error {{expected '(' after 'collapse'}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + #pragma omp taskloop collapse ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + #pragma omp taskloop collapse () // expected-error {{expected expression}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + #pragma omp taskloop collapse (4 // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-note {{as specified in 'collapse' clause}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}} + #pragma omp taskloop collapse (2+2)) // expected-warning {{extra tokens at the end of '#pragma omp taskloop' are ignored}} expected-note {{as specified in 'collapse' clause}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}} + #pragma omp taskloop collapse (foobool(1) > 0 ? 1 : 2) // expected-error {{expression is not an integral constant expression}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + // expected-error@+3 {{expression is not an integral constant expression}} + // expected-error@+2 2 {{directive '#pragma omp taskloop' cannot contain more than one 'collapse' clause}} + // expected-error@+1 2 {{argument to 'collapse' clause must be a positive integer value}} + #pragma omp taskloop collapse (foobool(argc)), collapse (true), collapse (-5) + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + #pragma omp taskloop collapse (S1) // expected-error {{'S1' does not refer to a value}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + // expected-error@+1 {{expression is not an integral constant expression}} + #pragma omp taskloop collapse (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + // expected-error@+3 {{statement after '#pragma omp taskloop' must be a for loop}} + // expected-note@+1 {{in instantiation of function template specialization 'tmain' requested here}} + #pragma omp taskloop collapse(collapse(tmain(argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}} + foo(); + #pragma omp taskloop collapse (2) // expected-note {{as specified in 'collapse' clause}} + foo(); // expected-error {{expected 2 for loops after '#pragma omp taskloop'}} + // expected-note@+1 {{in instantiation of function template specialization 'tmain' requested here}} + return tmain(argc, argv); +} + diff --git a/test/OpenMP/taskloop_firstprivate_messages.cpp b/test/OpenMP/taskloop_firstprivate_messages.cpp new file mode 100644 index 0000000000..e2e87e4697 --- /dev/null +++ b/test/OpenMP/taskloop_firstprivate_messages.cpp @@ -0,0 +1,313 @@ +// RUN: %clang_cc1 -verify -fopenmp %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; + +public: + S2() : a(0) {} + S2(const 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; + S3 &operator=(const S3 &s3); + +public: + S3() : a(0) {} // expected-note 2 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} + S3(S3 &s3) : a(s3.a) {} // expected-note 2 {{candidate constructor not viable: 1st argument ('const S3') would lose const qualifier}} +}; +const S3 c; +const S3 ca[5]; +extern const int f; +class S4 { + int a; + S4(); + S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}} + +public: + S4(int v) : a(v) {} +}; +class S5 { + int a; + S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}} + +public: + S5() : a(0) {} + S5(int v) : a(v) {} +}; +class S6 { + int a; + S6() : a(0) {} + +public: + S6(const S6 &s6) : a(s6.a) {} + S6(int v) : a(v) {} +}; + +S3 h; +#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} + +template +int foomain(int argc, char **argv) { + I e(4); + C g(5); + int i; + int &j = i; +#pragma omp parallel +#pragma omp taskloop firstprivate // expected-error {{expected '(' after 'firstprivate'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate() // expected-error {{expected expression}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(argc) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(S1) // expected-error {{'S1' does not refer to a value}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(argv[1]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel + { + int v = 0; + int i; +#pragma omp taskloop firstprivate(i) + for (int k = 0; k < argc; ++k) { + i = k; + v += i; + } + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp taskloop firstprivate(j) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop firstprivate(i) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel private(i) +#pragma omp taskloop firstprivate(i) // expected-note {{defined as firstprivate}} + for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be firstprivate, predetermined as private}} + foo(); +#pragma omp parallel reduction(+ : i) +#pragma omp taskloop firstprivate(i) // expected-note {{defined as firstprivate}} + for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be firstprivate, predetermined as private}} + foo(); + return 0; +} + +void bar(S4 a[2]) { +#pragma omp parallel +#pragma omp taskloop firstprivate(a) + for (int i = 0; i < 2; ++i) + foo(); +} + +namespace A { +double x; +#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} +} +namespace B { +using A::x; +} + +int main(int argc, char **argv) { + const int d = 5; + const int da[5] = {0}; + S4 e(4); + S5 g(5); + S3 m; + S6 n(2); + int i; + int &j = i; +#pragma omp parallel +#pragma omp taskloop firstprivate // expected-error {{expected '(' after 'firstprivate'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate() // expected-error {{expected expression}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(argc) + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(S1) // expected-error {{'S1' does not refer to a value}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{no matching constructor for initialization of 'S3'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(argv[1]) // expected-error {{expected variable name}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(2 * 2) // expected-error {{expected variable name}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(ba) // OK + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(da) // OK + for (i = 0; i < argc; ++i) + foo(); + int xa; +#pragma omp parallel +#pragma omp taskloop firstprivate(xa) // OK + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(S2::S2s) // OK + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(S2::S2sc) // OK + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp taskloop'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(m) // OK + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(i) // expected-note {{defined as firstprivate}} + for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be firstprivate, predetermined as private}} + foo(); +#pragma omp parallel shared(xa) +#pragma omp taskloop firstprivate(xa) // OK: may be firstprivate + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(j) + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(n) firstprivate(n) // OK + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel + { + int v = 0; + int i; +#pragma omp taskloop firstprivate(i) + for (int k = 0; k < argc; ++k) { + i = k; + v += i; + } + } +#pragma omp parallel private(i) +#pragma omp taskloop firstprivate(i) // expected-note {{defined as firstprivate}} + for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be firstprivate, predetermined as private}} + foo(); +#pragma omp parallel reduction(+ : i) +#pragma omp taskloop firstprivate(i) // expected-note {{defined as firstprivate}} + for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be firstprivate, predetermined as private}} + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} + for (i = 0; i < argc; ++i) + foo(); + static int si; +#pragma omp taskloop firstprivate(si) // OK + for (i = 0; i < argc; ++i) + si = i + 1; + + return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain' requested here}} +} + diff --git a/test/OpenMP/taskloop_lastprivate_messages.cpp b/test/OpenMP/taskloop_lastprivate_messages.cpp new file mode 100644 index 0000000000..ea8b3d9c61 --- /dev/null +++ b/test/OpenMP/taskloop_lastprivate_messages.cpp @@ -0,0 +1,287 @@ +// RUN: %clang_cc1 -verify -fopenmp %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; + +public: + S2() : a(0) {} + S2(S2 &s2) : a(s2.a) {} + const S2 &operator =(const S2&) const; + S2 &operator =(const S2&); + static float S2s; + static const float S2sc; +}; +const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}} +const S2 b; +const S2 ba[5]; +class S3 { + int a; + S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}} + +public: + S3() : a(0) {} + S3(S3 &s3) : a(s3.a) {} +}; +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 { + int a; + S4(); // expected-note 3 {{implicitly declared private here}} + S4(const S4 &s4); + +public: + S4(int v) : a(v) {} +}; +class S5 { + int a; + S5() : a(0) {} // expected-note {{implicitly declared private here}} + +public: + S5(const S5 &s5) : a(s5.a) {} + S5(int v) : a(v) {} +}; +class S6 { + int a; + S6() : a(0) {} + +public: + S6(const S6 &s6) : a(s6.a) {} + S6(int v) : a(v) {} +}; + +S3 h; +#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} + +template +int foomain(int argc, char **argv) { + I e(4); + I g(5); + int i; + int &j = i; +#pragma omp parallel +#pragma omp taskloop lastprivate // expected-error {{expected '(' after 'lastprivate'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate() // expected-error {{expected expression}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(argc) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(S1) // expected-error {{'S1' does not refer to a value}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(argv[1]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel + { + int v = 0; + int i; +#pragma omp taskloop lastprivate(i) + for (int k = 0; k < argc; ++k) { + i = k; + v += i; + } + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp taskloop lastprivate(j) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel +#pragma omp taskloop lastprivate(i) + for (int k = 0; k < argc; ++k) + ++k; + return 0; +} + +void bar(S4 a[2]) { +#pragma omp parallel +#pragma omp taskloop lastprivate(a) + for (int i = 0; i < 2; ++i) + foo(); +} + +namespace A { +double x; +#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} +} +namespace B { +using A::x; +} + +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); + S5 g(5); + S3 m; + S6 n(2); + int i; + int &j = i; +#pragma omp parallel +#pragma omp taskloop lastprivate // expected-error {{expected '(' after 'lastprivate'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate() // expected-error {{expected expression}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(argc) + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(S1) // expected-error {{'S1' does not refer to a value}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be lastprivate}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(argv[1]) // expected-error {{expected variable name}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(2 * 2) // expected-error {{expected variable name}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(ba) + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(ca) // expected-error {{shared variable cannot be lastprivate}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(da) // expected-error {{shared variable cannot be lastprivate}} + for (i = 0; i < argc; ++i) + foo(); + int xa; +#pragma omp parallel +#pragma omp taskloop lastprivate(xa) // OK + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(S2::S2s) + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(S2::S2sc) // expected-error {{shared variable cannot be lastprivate}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp taskloop'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be lastprivate}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(i) + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel private(xa) +#pragma omp taskloop lastprivate(xa) + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel reduction(+ : xa) +#pragma omp taskloop lastprivate(xa) + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(j) + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}} + for (i = 0; i < argc; ++i) + foo(); +#pragma omp parallel +#pragma omp taskloop lastprivate(n) firstprivate(n) // OK + for (i = 0; i < argc; ++i) + foo(); + static int si; +#pragma omp taskloop lastprivate(si) // OK + for (i = 0; i < argc; ++i) + si = i + 1; + return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain' requested here}} +} diff --git a/test/OpenMP/taskloop_loop_messages.cpp b/test/OpenMP/taskloop_loop_messages.cpp new file mode 100644 index 0000000000..3ff8005f7f --- /dev/null +++ b/test/OpenMP/taskloop_loop_messages.cpp @@ -0,0 +1,736 @@ +// RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s + +class S { + int a; + S() : a(0) {} + +public: + S(int v) : a(v) {} + S(const S &s) : a(s.a) {} +}; + +static int sii; +#pragma omp threadprivate(sii) +static int globalii; + +// Currently, we cannot use "0" for global register variables. +// register int reg0 __asm__("0"); +int reg0; + +int test_iteration_spaces() { + const int N = 100; + float a[N], b[N], c[N]; + int ii, jj, kk; + float fii; + double dii; + register int reg; // expected-warning {{'register' storage class specifier is deprecated}} +#pragma omp parallel +#pragma omp taskloop + for (int i = 0; i < 10; i += 1) { + c[i] = a[i] + b[i]; + } +#pragma omp parallel +#pragma omp taskloop + for (char i = 0; i < 10; i++) { + c[i] = a[i] + b[i]; + } +#pragma omp parallel +#pragma omp taskloop + for (char i = 0; i < 10; i += '\1') { + c[i] = a[i] + b[i]; + } +#pragma omp parallel +#pragma omp taskloop + for (long long i = 0; i < 10; i++) { + c[i] = a[i] + b[i]; + } +#pragma omp parallel +// expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}} +#pragma omp taskloop + for (long long i = 0; i < 10; i += 1.5) { + c[i] = a[i] + b[i]; + } +#pragma omp parallel +#pragma omp taskloop + for (long long i = 0; i < 'z'; i += 1u) { + c[i] = a[i] + b[i]; + } +#pragma omp parallel +// expected-error@+2 {{variable must be of integer or random access iterator type}} +#pragma omp taskloop + for (float fi = 0; fi < 10.0; fi++) { + c[(int)fi] = a[(int)fi] + b[(int)fi]; + } +#pragma omp parallel +// expected-error@+2 {{variable must be of integer or random access iterator type}} +#pragma omp taskloop + for (double fi = 0; fi < 10.0; fi++) { + c[(int)fi] = a[(int)fi] + b[(int)fi]; + } +#pragma omp parallel +// expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (int &ref = ii; ref < 10; ref++) { + } +#pragma omp parallel +// expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (int i; i < 10; i++) + c[i] = a[i]; + +#pragma omp parallel +// expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (int i = 0, j = 0; i < 10; ++i) + c[i] = a[i]; + +#pragma omp parallel +// expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (; ii < 10; ++ii) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-warning@+3 {{expression result unused}} +// expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (ii + 1; ii < 10; ++ii) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (c[ii] = 0; ii < 10; ++ii) + c[ii] = a[ii]; + +#pragma omp parallel +// Ok to skip parenthesises. +#pragma omp taskloop + for (((ii)) = 0; ii < 10; ++ii) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} +#pragma omp taskloop + for (int i = 0; i; i++) + c[i] = a[i]; + +#pragma omp parallel +// expected-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}} +#pragma omp taskloop + for (int i = 0; jj < kk; ii++) + c[i] = a[i]; + +#pragma omp parallel +// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} +#pragma omp taskloop + for (int i = 0; !!i; i++) + c[i] = a[i]; + +#pragma omp parallel +// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} +#pragma omp taskloop + for (int i = 0; i != 1; i++) + c[i] = a[i]; + +#pragma omp parallel +// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} +#pragma omp taskloop + for (int i = 0;; i++) + c[i] = a[i]; + +#pragma omp parallel +// Ok. +#pragma omp taskloop + for (int i = 11; i > 10; i--) + c[i] = a[i]; + +#pragma omp parallel +// Ok. +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + c[i] = a[i]; + +#pragma omp parallel +// Ok. +#pragma omp taskloop + for (ii = 0; ii < 10; ++ii) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} +#pragma omp taskloop + for (ii = 0; ii < 10; ++jj) + c[ii] = a[jj]; + +#pragma omp parallel +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} +#pragma omp taskloop + for (ii = 0; ii < 10; ++++ii) + c[ii] = a[ii]; + +#pragma omp parallel +// Ok but undefined behavior (in general, cannot check that incr +// is really loop-invariant). +#pragma omp taskloop + for (ii = 0; ii < 10; ii = ii + ii) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}} +#pragma omp taskloop + for (ii = 0; ii < 10; ii = ii + 1.0f) + c[ii] = a[ii]; + +#pragma omp parallel +// Ok - step was converted to integer type. +#pragma omp taskloop + for (ii = 0; ii < 10; ii = ii + (int)1.1f) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} +#pragma omp taskloop + for (ii = 0; ii < 10; jj = ii + 2) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-warning@+3 {{relational comparison result unused}} +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} +#pragma omp taskloop + for (ii = 0; ii<10; jj> kk + 2) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} +#pragma omp taskloop + for (ii = 0; ii < 10;) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-warning@+3 {{expression result unused}} +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} +#pragma omp taskloop + for (ii = 0; ii < 10; !ii) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} +#pragma omp taskloop + for (ii = 0; ii < 10; ii ? ++ii : ++jj) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}} +#pragma omp taskloop + for (ii = 0; ii < 10; ii = ii < 10) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be positive due to this condition}} +// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (ii = 0; ii < 10; ii = ii + 0) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be positive due to this condition}} +// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45)) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be positive due to this condition}} +// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (ii = 0; (ii) < 10; ii -= 25) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be positive due to this condition}} +// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (ii = 0; (ii < 10); ii -= 0) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be negative due to this condition}} +// expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (ii = 0; ii > 10; (ii += 0)) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be positive due to this condition}} +// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii)) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be negative due to this condition}} +// expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}} +#pragma omp taskloop + for ((ii = 0); ii > 10; (ii -= 0)) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be positive due to this condition}} +// expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (ii = 0; (ii < 10); (ii -= 0)) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-note@+2 {{defined as firstprivate}} +// expected-error@+2 {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be firstprivate, predetermined as private}} +#pragma omp taskloop firstprivate(ii) + for (ii = 0; ii < 10; ii++) + c[ii] = a[ii]; + +#pragma omp parallel +// expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp taskloop'}} +// expected-note@+1 {{defined as linear}} +#pragma omp taskloop linear(ii) +// expected-error@+1 {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be linear, predetermined as private}} + for (ii = 0; ii < 10; ii++) + c[ii] = a[ii]; + +#pragma omp parallel +#pragma omp taskloop private(ii) + for (ii = 0; ii < 10; ii++) + c[ii] = a[ii]; + +#pragma omp parallel +#pragma omp taskloop lastprivate(ii) + for (ii = 0; ii < 10; ii++) + c[ii] = a[ii]; + +#pragma omp parallel + { +#pragma omp taskloop + for (sii = 0; sii < 10; sii += 1) + c[sii] = a[sii]; + } + +#pragma omp parallel + { +#pragma omp taskloop + for (reg0 = 0; reg0 < 10; reg0 += 1) + c[reg0] = a[reg0]; + } + +#pragma omp parallel + { +#pragma omp taskloop + for (reg = 0; reg < 10; reg += 1) + c[reg] = a[reg]; + } + +#pragma omp parallel + { +#pragma omp taskloop + for (globalii = 0; globalii < 10; globalii += 1) + c[globalii] = a[globalii]; + } + +#pragma omp parallel + { +#pragma omp taskloop collapse(2) + for (ii = 0; ii < 10; ii += 1) + for (globalii = 0; globalii < 10; globalii += 1) + c[globalii] += a[globalii] + ii; + } + +#pragma omp parallel +// expected-error@+2 {{statement after '#pragma omp taskloop' must be a for loop}} +#pragma omp taskloop + for (auto &item : a) { + item = item + 1; + } + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be positive due to this condition}} +// expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (unsigned i = 9; i < 10; i--) { + c[i] = a[i] + b[i]; + } + + int(*lb)[4] = nullptr; +#pragma omp parallel +#pragma omp taskloop + for (int(*p)[4] = lb; p < lb + 8; ++p) { + } + +#pragma omp parallel +// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (int a{0}; a < 10; ++a) { + } + + return 0; +} + +// Iterators allowed in openmp for-loops. +namespace std { +struct random_access_iterator_tag {}; +template +struct iterator_traits { + typedef typename Iter::difference_type difference_type; + typedef typename Iter::iterator_category iterator_category; +}; +template +typename iterator_traits::difference_type +distance(Iter first, Iter last) { return first - last; } +} +class Iter0 { +public: + Iter0() {} + Iter0(const Iter0 &) {} + Iter0 operator++() { return *this; } + Iter0 operator--() { return *this; } + bool operator<(Iter0 a) { return true; } +}; +// expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}} +// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}} +int operator-(Iter0 a, Iter0 b) { return 0; } +class Iter1 { +public: + Iter1(float f = 0.0f, double d = 0.0) {} + Iter1(const Iter1 &) {} + Iter1 operator++() { return *this; } + Iter1 operator--() { return *this; } + bool operator<(Iter1 a) { return true; } + bool operator>=(Iter1 a) { return false; } +}; +class GoodIter { +public: + GoodIter() {} + GoodIter(const GoodIter &) {} + GoodIter(int fst, int snd) {} + GoodIter &operator=(const GoodIter &that) { return *this; } + GoodIter &operator=(const Iter0 &that) { return *this; } + GoodIter &operator+=(int x) { return *this; } + GoodIter &operator-=(int x) { return *this; } + explicit GoodIter(void *) {} + GoodIter operator++() { return *this; } + GoodIter operator--() { return *this; } + bool operator!() { return true; } + bool operator<(GoodIter a) { return true; } + bool operator<=(GoodIter a) { return true; } + bool operator>=(GoodIter a) { return false; } + typedef int difference_type; + typedef std::random_access_iterator_tag iterator_category; +}; +// expected-note@+2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 2nd argument}} +// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} +int operator-(GoodIter a, GoodIter b) { return 0; } +// expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}} +GoodIter operator-(GoodIter a) { return a; } +// expected-note@+2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 2nd argument}} +// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} +GoodIter operator-(GoodIter a, int v) { return GoodIter(); } +// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}} +GoodIter operator+(GoodIter a, int v) { return GoodIter(); } +// expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}} +// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}} +GoodIter operator-(int v, GoodIter a) { return GoodIter(); } +// expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}} +GoodIter operator+(int v, GoodIter a) { return GoodIter(); } + +int test_with_random_access_iterator() { + GoodIter begin, end; + Iter0 begin0, end0; +#pragma omp parallel +#pragma omp taskloop + for (GoodIter I = begin; I < end; ++I) + ++I; +#pragma omp parallel +// expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (GoodIter &I = begin; I < end; ++I) + ++I; +#pragma omp parallel +#pragma omp taskloop + for (GoodIter I = begin; I >= end; --I) + ++I; +#pragma omp parallel +// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (GoodIter I(begin); I < end; ++I) + ++I; +#pragma omp parallel +// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (GoodIter I(nullptr); I < end; ++I) + ++I; +#pragma omp parallel +// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (GoodIter I(0); I < end; ++I) + ++I; +#pragma omp parallel +// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (GoodIter I(1, 2); I < end; ++I) + ++I; +#pragma omp parallel +#pragma omp taskloop + for (begin = GoodIter(0); begin < end; ++begin) + ++begin; +// expected-error@+4 {{invalid operands to binary expression ('GoodIter' and 'Iter0')}} +// expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} +#pragma omp parallel +#pragma omp taskloop + for (begin = begin0; begin < end; ++begin) + ++begin; +#pragma omp parallel +// expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (++begin; begin < end; ++begin) + ++begin; +#pragma omp parallel +#pragma omp taskloop + for (begin = end; begin < end; ++begin) + ++begin; +#pragma omp parallel +// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} +#pragma omp taskloop + for (GoodIter I = begin; I - I; ++I) + ++I; +#pragma omp parallel +// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} +#pragma omp taskloop + for (GoodIter I = begin; begin < end; ++I) + ++I; +#pragma omp parallel +// expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} +#pragma omp taskloop + for (GoodIter I = begin; !I; ++I) + ++I; +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be negative due to this condition}} +// expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (GoodIter I = begin; I >= end; I = I + 1) + ++I; +#pragma omp parallel +#pragma omp taskloop + for (GoodIter I = begin; I >= end; I = I - 1) + ++I; +#pragma omp parallel +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} +#pragma omp taskloop + for (GoodIter I = begin; I >= end; I = -I) + ++I; +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be negative due to this condition}} +// expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (GoodIter I = begin; I >= end; I = 2 + I) + ++I; +#pragma omp parallel +// expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} +#pragma omp taskloop + for (GoodIter I = begin; I >= end; I = 2 - I) + ++I; +// In the following example, we cannot update the loop variable using '+=' +// expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}} +#pragma omp parallel +#pragma omp taskloop + for (Iter0 I = begin0; I < end0; ++I) + ++I; +#pragma omp parallel +// Initializer is constructor without params. +// expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}} +// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (Iter0 I; I < end0; ++I) + ++I; + Iter1 begin1, end1; +// expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} +// expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} +#pragma omp parallel +#pragma omp taskloop + for (Iter1 I = begin1; I < end1; ++I) + ++I; +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be negative due to this condition}} +// expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (Iter1 I = begin1; I >= end1; ++I) + ++I; +#pragma omp parallel +// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}} +// expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} +// Initializer is constructor with all default params. +// expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} +#pragma omp taskloop + for (Iter1 I; I < end1; ++I) { + } + return 0; +} + +template +class TC { +public: + int dotest_lt(IT begin, IT end) { +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be positive due to this condition}} +// expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (IT I = begin; I < end; I = I + ST) { + ++I; + } +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be positive due to this condition}} +// expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (IT I = begin; I <= end; I += ST) { + ++I; + } +#pragma omp parallel +#pragma omp taskloop + for (IT I = begin; I < end; ++I) { + ++I; + } + } + + static IT step() { + return IT(ST); + } +}; +template +int dotest_gt(IT begin, IT end) { +#pragma omp parallel +// expected-note@+3 2 {{loop step is expected to be negative due to this condition}} +// expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (IT I = begin; I >= end; I = I + ST) { + ++I; + } +#pragma omp parallel +// expected-note@+3 2 {{loop step is expected to be negative due to this condition}} +// expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (IT I = begin; I >= end; I += ST) { + ++I; + } + +#pragma omp parallel +// expected-note@+3 {{loop step is expected to be negative due to this condition}} +// expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} +#pragma omp taskloop + for (IT I = begin; I >= end; ++I) { + ++I; + } + +#pragma omp parallel +#pragma omp taskloop + for (IT I = begin; I < end; I += TC::step()) { + ++I; + } +} + +void test_with_template() { + GoodIter begin, end; + TC t1; + TC t2; + t1.dotest_lt(begin, end); + t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC::dotest_lt' requested here}} + dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt' requested here}} + dotest_gt(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt' requested here}} +} + +void test_loop_break() { + const int N = 100; + float a[N], b[N], c[N]; +#pragma omp parallel +#pragma omp taskloop + for (int i = 0; i < 10; i++) { + c[i] = a[i] + b[i]; + for (int j = 0; j < 10; ++j) { + if (a[i] > b[j]) + break; // OK in nested loop + } + switch (i) { + case 1: + b[i]++; + break; + default: + break; + } + if (c[i] > 10) + break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} + + if (c[i] > 11) + break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} + } + +#pragma omp parallel +#pragma omp taskloop + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + c[i] = a[i] + b[i]; + if (c[i] > 10) { + if (c[i] < 20) { + break; // OK + } + } + } + } +} + +void test_loop_eh() { + const int N = 100; + float a[N], b[N], c[N]; +#pragma omp parallel +#pragma omp taskloop + for (int i = 0; i < 10; i++) { + c[i] = a[i] + b[i]; + try { + for (int j = 0; j < 10; ++j) { + if (a[i] > b[j]) + throw a[i]; + } + throw a[i]; + } catch (float f) { + if (f > 0.1) + throw a[i]; + return; // expected-error {{cannot return from OpenMP region}} + } + switch (i) { + case 1: + b[i]++; + break; + default: + break; + } + for (int j = 0; j < 10; j++) { + if (c[i] > 10) + throw c[i]; + } + } + if (c[9] > 10) + throw c[9]; // OK + +#pragma omp parallel +#pragma omp taskloop + for (int i = 0; i < 10; ++i) { + struct S { + void g() { throw 0; } + }; + } +} + +void test_loop_firstprivate_lastprivate() { + S s(4); +#pragma omp parallel +#pragma omp taskloop lastprivate(s) firstprivate(s) + for (int i = 0; i < 16; ++i) + ; +} + diff --git a/test/OpenMP/taskloop_misc_messages.c b/test/OpenMP/taskloop_misc_messages.c new file mode 100644 index 0000000000..da5b3a4681 --- /dev/null +++ b/test/OpenMP/taskloop_misc_messages.c @@ -0,0 +1,369 @@ +// RUN: %clang_cc1 -fsyntax-only -fopenmp -triple x86_64-unknown-unknown -verify %s + +// expected-error@+1 {{unexpected OpenMP directive '#pragma omp taskloop'}} +#pragma omp taskloop + +// expected-error@+1 {{unexpected OpenMP directive '#pragma omp taskloop'}} +#pragma omp taskloop foo + +void test_no_clause() { + int i; +#pragma omp taskloop + for (i = 0; i < 16; ++i) + ; + +// expected-error@+2 {{statement after '#pragma omp taskloop' must be a for loop}} +#pragma omp taskloop + ++i; +} + +void test_branch_protected_scope() { + int i = 0; +L1: + ++i; + + int x[24]; + +#pragma omp parallel +#pragma omp taskloop + for (i = 0; i < 16; ++i) { + if (i == 5) + goto L1; // expected-error {{use of undeclared label 'L1'}} + else if (i == 6) + return; // expected-error {{cannot return from OpenMP region}} + else if (i == 7) + goto L2; + else if (i == 8) { + L2: + x[i]++; + } + } + + if (x[0] == 0) + goto L2; // expected-error {{use of undeclared label 'L2'}} + else if (x[1] == 1) + goto L1; +} + +void test_invalid_clause() { + int i; +#pragma omp parallel +// expected-warning@+1 {{extra tokens at the end of '#pragma omp taskloop' are ignored}} +#pragma omp taskloop foo bar + for (i = 0; i < 16; ++i) + ; +} + +void test_non_identifiers() { + int i, x; + +#pragma omp parallel +// expected-warning@+1 {{extra tokens at the end of '#pragma omp taskloop' are ignored}} +#pragma omp taskloop; + for (i = 0; i < 16; ++i) + ; +// expected-warning@+3 {{extra tokens at the end of '#pragma omp taskloop' are ignored}} +// expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp taskloop'}} +#pragma omp parallel +#pragma omp taskloop linear(x); + for (i = 0; i < 16; ++i) + ; + +#pragma omp parallel +// expected-warning@+1 {{extra tokens at the end of '#pragma omp taskloop' are ignored}} +#pragma omp taskloop private(x); + for (i = 0; i < 16; ++i) + ; + +#pragma omp parallel +// expected-warning@+1 {{extra tokens at the end of '#pragma omp taskloop' are ignored}} +#pragma omp taskloop, private(x); + for (i = 0; i < 16; ++i) + ; +} + +extern int foo(); + +void test_collapse() { + int i; +#pragma omp parallel +// expected-error@+1 {{expected '('}} +#pragma omp taskloop collapse + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}} +#pragma omp taskloop collapse( + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp taskloop collapse() + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}} +#pragma omp taskloop collapse(, + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}} +#pragma omp taskloop collapse(, ) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-warning@+2 {{extra tokens at the end of '#pragma omp taskloop' are ignored}} +// expected-error@+1 {{expected '('}} +#pragma omp taskloop collapse 4) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+2 {{expected ')'}} +// expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}} +#pragma omp taskloop collapse(4 + for (i = 0; i < 16; ++i) + ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}} +#pragma omp parallel +// expected-error@+2 {{expected ')'}} +// expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}} +#pragma omp taskloop collapse(4, + for (i = 0; i < 16; ++i) + ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}} +#pragma omp parallel +// expected-error@+2 {{expected ')'}} +// expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}} +#pragma omp taskloop collapse(4, ) + for (i = 0; i < 16; ++i) + ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}} +#pragma omp parallel +// expected-note@+1 {{as specified in 'collapse' clause}} +#pragma omp taskloop collapse(4) + for (i = 0; i < 16; ++i) + ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}} +#pragma omp parallel +// expected-error@+2 {{expected ')'}} +// expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}} +#pragma omp taskloop collapse(4 4) + for (i = 0; i < 16; ++i) + ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}} +#pragma omp parallel +// expected-error@+2 {{expected ')'}} +// expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}} +#pragma omp taskloop collapse(4, , 4) + for (i = 0; i < 16; ++i) + ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}} +#pragma omp parallel +#pragma omp taskloop collapse(4) + for (int i1 = 0; i1 < 16; ++i1) + for (int i2 = 0; i2 < 16; ++i2) + for (int i3 = 0; i3 < 16; ++i3) + for (int i4 = 0; i4 < 16; ++i4) + foo(); +#pragma omp parallel +// expected-error@+2 {{expected ')'}} +// expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}} +#pragma omp taskloop collapse(4, 8) + for (i = 0; i < 16; ++i) + ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}} +#pragma omp parallel +// expected-error@+1 {{expression is not an integer constant expression}} +#pragma omp taskloop collapse(2.5) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expression is not an integer constant expression}} +#pragma omp taskloop collapse(foo()) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{argument to 'collapse' clause must be a positive integer value}} +#pragma omp taskloop collapse(-5) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{argument to 'collapse' clause must be a positive integer value}} +#pragma omp taskloop collapse(0) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{argument to 'collapse' clause must be a positive integer value}} +#pragma omp taskloop collapse(5 - 5) + for (i = 0; i < 16; ++i) + ; +} + +void test_private() { + int i; +#pragma omp parallel +// expected-error@+2 {{expected expression}} +// expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}} +#pragma omp taskloop private( + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} +// expected-error@+1 2 {{expected expression}} +#pragma omp taskloop private(, + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 2 {{expected expression}} +#pragma omp taskloop private(, ) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp taskloop private() + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp taskloop private(int) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected variable name}} +#pragma omp taskloop private(0) + for (i = 0; i < 16; ++i) + ; + + int x, y, z; +#pragma omp parallel +#pragma omp taskloop private(x) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +#pragma omp taskloop private(x, y) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +#pragma omp taskloop private(x, y, z) + for (i = 0; i < 16; ++i) { + x = y * i + z; + } +} + +void test_lastprivate() { + int i; +#pragma omp parallel +// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} +// expected-error@+1 {{expected expression}} +#pragma omp taskloop lastprivate( + for (i = 0; i < 16; ++i) + ; + +#pragma omp parallel +// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} +// expected-error@+1 2 {{expected expression}} +#pragma omp taskloop lastprivate(, + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 2 {{expected expression}} +#pragma omp taskloop lastprivate(, ) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp taskloop lastprivate() + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp taskloop lastprivate(int) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected variable name}} +#pragma omp taskloop lastprivate(0) + for (i = 0; i < 16; ++i) + ; + + int x, y, z; +#pragma omp parallel +#pragma omp taskloop lastprivate(x) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +#pragma omp taskloop lastprivate(x, y) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +#pragma omp taskloop lastprivate(x, y, z) + for (i = 0; i < 16; ++i) + ; +} + +void test_firstprivate() { + int i; +#pragma omp parallel +// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} +// expected-error@+1 {{expected expression}} +#pragma omp taskloop firstprivate( + for (i = 0; i < 16; ++i) + ; + +#pragma omp parallel +// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} +// expected-error@+1 2 {{expected expression}} +#pragma omp taskloop firstprivate(, + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 2 {{expected expression}} +#pragma omp taskloop firstprivate(, ) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp taskloop firstprivate() + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp taskloop firstprivate(int) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +// expected-error@+1 {{expected variable name}} +#pragma omp taskloop firstprivate(0) + for (i = 0; i < 16; ++i) + ; + + int x, y, z; +#pragma omp parallel +#pragma omp taskloop lastprivate(x) firstprivate(x) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +#pragma omp taskloop lastprivate(x, y) firstprivate(x, y) + for (i = 0; i < 16; ++i) + ; +#pragma omp parallel +#pragma omp taskloop lastprivate(x, y, z) firstprivate(x, y, z) + for (i = 0; i < 16; ++i) + ; +} + +void test_loop_messages() { + float a[100], b[100], c[100]; +#pragma omp parallel +// expected-error@+2 {{variable must be of integer or pointer type}} +#pragma omp taskloop + for (float fi = 0; fi < 10.0; fi++) { + c[(int)fi] = a[(int)fi] + b[(int)fi]; + } +#pragma omp parallel +// expected-error@+2 {{variable must be of integer or pointer type}} +#pragma omp taskloop + for (double fi = 0; fi < 10.0; fi++) { + c[(int)fi] = a[(int)fi] + b[(int)fi]; + } + + // expected-warning@+2 {{OpenMP loop iteration variable cannot have more than 64 bits size and will be narrowed}} + #pragma omp taskloop + for (__int128 ii = 0; ii < 10; ii++) { + c[ii] = a[ii] + b[ii]; + } +} + diff --git a/test/OpenMP/taskloop_private_messages.cpp b/test/OpenMP/taskloop_private_messages.cpp new file mode 100644 index 0000000000..3d00d3f252 --- /dev/null +++ b/test/OpenMP/taskloop_private_messages.cpp @@ -0,0 +1,195 @@ +// RUN: %clang_cc1 -verify -fopenmp %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; + +public: + S2() : a(0) {} +}; +const S2 b; +const S2 ba[5]; +class S3 { + int a; + +public: + S3() : a(0) {} +}; +const S3 ca[5]; +class S4 { + int a; + S4(); // expected-note {{implicitly declared private here}} + +public: + S4(int v) : a(v) {} +}; +class S5 { + int a; + S5() : a(0) {} // expected-note {{implicitly declared private here}} + +public: + S5(int v) : a(v) {} +}; + +S3 h; +#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} + +template +int foomain(I argc, C **argv) { + I e(4); + I g(5); + int i; + int &j = i; +#pragma omp taskloop private // expected-error {{expected '(' after 'private'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private() // expected-error {{expected expression}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argc) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(S1) // expected-error {{'S1' does not refer to a value}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(a, b) // expected-error {{private variable with incomplete type 'S1'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argv[1]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(e, g) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(h) // expected-error {{threadprivate or thread local variable cannot be private}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop shared(i) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel + { + int v = 0; + int i; +#pragma omp taskloop private(i) + for (int k = 0; k < argc; ++k) { + i = k; + v += i; + } + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp taskloop private(j) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(i) + for (int k = 0; k < argc; ++k) + ++k; + return 0; +} + +void bar(S4 a[2]) { +#pragma omp parallel +#pragma omp taskloop private(a) + for (int i = 0; i < 2; ++i) + foo(); +} + +namespace A { +double x; +#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} +} +namespace B { +using A::x; +} + +int main(int argc, char **argv) { + S4 e(4); + S5 g(5); + int i; + int &j = i; +#pragma omp taskloop private // expected-error {{expected '(' after 'private'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private() // expected-error {{expected expression}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argc) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(S1) // expected-error {{'S1' does not refer to a value}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(a, b) // expected-error {{private variable with incomplete type 'S1'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(argv[1]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(h) // expected-error {{threadprivate or thread local variable cannot be private}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}} + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop shared(i) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp parallel + { + int i; +#pragma omp taskloop private(i) + for (int k = 0; k < argc; ++k) + ++k; + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp taskloop private(j) + for (int k = 0; k < argc; ++k) + ++k; +#pragma omp taskloop private(i) + for (int k = 0; k < argc; ++k) + ++k; + static int si; +#pragma omp taskloop private(si) // OK + for(int k = 0; k < argc; ++k) + si = k + 1; + + return 0; +} + diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 1141f92881..a92892a580 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1942,6 +1942,7 @@ public: void VisitOMPTargetDirective(const OMPTargetDirective *D); void VisitOMPTargetDataDirective(const OMPTargetDataDirective *D); void VisitOMPTeamsDirective(const OMPTeamsDirective *D); + void VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D); private: void AddDeclarationNameInfo(const Stmt *S); @@ -2607,6 +2608,10 @@ void EnqueueVisitor::VisitOMPCancelDirective(const OMPCancelDirective *D) { VisitOMPExecutableDirective(D); } +void EnqueueVisitor::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D) { + VisitOMPLoopDirective(D); +} + void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) { EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S); } @@ -4463,6 +4468,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { return cxstring::createRef("OMPCancellationPointDirective"); case CXCursor_OMPCancelDirective: return cxstring::createRef("OMPCancelDirective"); + case CXCursor_OMPTaskLoopDirective: + return cxstring::createRef("OMPTaskLoopDirective"); case CXCursor_OverloadCandidate: return cxstring::createRef("OverloadCandidate"); case CXCursor_TypeAliasTemplateDecl: diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index 6b4a30e545..5c4b8ccd3e 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -607,6 +607,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent, case Stmt::OMPCancelDirectiveClass: K = CXCursor_OMPCancelDirective; break; + case Stmt::OMPTaskLoopDirectiveClass: + K = CXCursor_OMPTaskLoopDirective; + break; } CXCursor C = { K, 0, { Parent, S, TU } }; -- 2.40.0