diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -2570,7 +2570,11 @@ */ CXCursor_OMPParallelMasterTaskLoopSimdDirective = 284, - CXCursor_LastStmt = CXCursor_OMPParallelMasterTaskLoopSimdDirective, + /** OpenMP parallel master directive. + */ + CXCursor_OMPParallelMasterDirective = 285, + + CXCursor_LastStmt = CXCursor_OMPParallelMasterDirective, /** * Cursor that represents the translation unit itself. diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2752,6 +2752,9 @@ DEF_TRAVERSE_STMT(OMPParallelForSimdDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) +DEF_TRAVERSE_STMT(OMPParallelMasterDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) + DEF_TRAVERSE_STMT(OMPParallelSectionsDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -1842,6 +1842,55 @@ } }; +/// This represents '#pragma omp parallel master' directive. +/// +/// \code +/// #pragma omp parallel master private(a,b) +/// \endcode +/// In this example directive '#pragma omp parallel master' has clauses +/// 'private' with the variables 'a' and 'b' +/// +class OMPParallelMasterDirective : public OMPExecutableDirective { + friend class ASTStmtReader; + + OMPParallelMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc, + unsigned NumClauses) + : OMPExecutableDirective(this, OMPParallelMasterDirectiveClass, + OMPD_parallel_master, StartLoc, EndLoc, + NumClauses, 1) {} + + explicit OMPParallelMasterDirective(unsigned NumClauses) + : OMPExecutableDirective(this, OMPParallelMasterDirectiveClass, + OMPD_parallel_master, SourceLocation(), + SourceLocation(), NumClauses, 1) {} + +public: + /// Creates directive with a list of \a Clauses. + /// + /// \param C AST context. + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending Location of the directive. + /// \param Clauses List of clauses. + /// \param AssociatedStmt Statement, associated with the directive. + /// + static OMPParallelMasterDirective * + Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, + ArrayRef Clauses, Stmt *AssociatedStmt); + + /// Creates an empty directive with the place for \a NumClauses + /// clauses. + /// + /// \param C AST context. + /// \param NumClauses Number of clauses. + /// + static OMPParallelMasterDirective * + CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); + + static bool classof(const Stmt *T) { + return T->getStmtClass() == OMPParallelMasterDirectiveClass; + } +}; + /// This represents '#pragma omp parallel sections' directive. /// /// \code diff --git a/clang/include/clang/Basic/OpenMPKinds.def b/clang/include/clang/Basic/OpenMPKinds.def --- a/clang/include/clang/Basic/OpenMPKinds.def +++ b/clang/include/clang/Basic/OpenMPKinds.def @@ -44,6 +44,9 @@ #ifndef OPENMP_PARALLEL_FOR_SIMD_CLAUSE # define OPENMP_PARALLEL_FOR_SIMD_CLAUSE(Name) #endif +#ifndef OPENMP_PARALLEL_MASTER_CLAUSE +# define OPENMP_PARALLEL_MASTER_CLAUSE(Name) +#endif #ifndef OPENMP_PARALLEL_SECTIONS_CLAUSE # define OPENMP_PARALLEL_SECTIONS_CLAUSE(Name) #endif @@ -257,6 +260,7 @@ OPENMP_DIRECTIVE_EXT(target_update, "target update") OPENMP_DIRECTIVE_EXT(parallel_for, "parallel for") OPENMP_DIRECTIVE_EXT(parallel_for_simd, "parallel for simd") +OPENMP_DIRECTIVE_EXT(parallel_master, "parallel master") OPENMP_DIRECTIVE_EXT(parallel_sections, "parallel sections") OPENMP_DIRECTIVE_EXT(for_simd, "for simd") OPENMP_DIRECTIVE_EXT(cancellation_point, "cancellation point") @@ -501,6 +505,18 @@ OPENMP_PARALLEL_FOR_SIMD_CLAUSE(ordered) OPENMP_PARALLEL_FOR_SIMD_CLAUSE(allocate) +// Clauses allowed for OpenMP directive 'parallel master'. +OPENMP_PARALLEL_MASTER_CLAUSE(if) +OPENMP_PARALLEL_MASTER_CLAUSE(num_threads) +OPENMP_PARALLEL_MASTER_CLAUSE(default) +OPENMP_PARALLEL_MASTER_CLAUSE(private) +OPENMP_PARALLEL_MASTER_CLAUSE(firstprivate) +OPENMP_PARALLEL_MASTER_CLAUSE(shared) +OPENMP_PARALLEL_MASTER_CLAUSE(copyin) +OPENMP_PARALLEL_MASTER_CLAUSE(reduction) +OPENMP_PARALLEL_MASTER_CLAUSE(proc_bind) +OPENMP_PARALLEL_MASTER_CLAUSE(allocate) + // Clauses allowed for OpenMP directive 'parallel sections'. OPENMP_PARALLEL_SECTIONS_CLAUSE(if) OPENMP_PARALLEL_SECTIONS_CLAUSE(num_threads) @@ -1131,6 +1147,7 @@ #undef OPENMP_PARALLEL_CLAUSE #undef OPENMP_PARALLEL_FOR_CLAUSE #undef OPENMP_PARALLEL_FOR_SIMD_CLAUSE +#undef OPENMP_PARALLEL_MASTER_CLAUSE #undef OPENMP_PARALLEL_SECTIONS_CLAUSE #undef OPENMP_TASK_CLAUSE #undef OPENMP_ATOMIC_CLAUSE diff --git a/clang/include/clang/Basic/StmtNodes.td b/clang/include/clang/Basic/StmtNodes.td --- a/clang/include/clang/Basic/StmtNodes.td +++ b/clang/include/clang/Basic/StmtNodes.td @@ -223,6 +223,7 @@ def OMPCriticalDirective : StmtNode; def OMPParallelForDirective : StmtNode; def OMPParallelForSimdDirective : StmtNode; +def OMPParallelMasterDirective : StmtNode; def OMPParallelSectionsDirective : StmtNode; def OMPTaskDirective : StmtNode; def OMPTaskyieldDirective : StmtNode; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9565,6 +9565,12 @@ StmtResult ActOnOpenMPParallelForSimdDirective( ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); + /// Called on well-formed '\#pragma omp parallel master' after + /// parsing of the associated statement. + StmtResult ActOnOpenMPParallelMasterDirective(ArrayRef Clauses, + Stmt *AStmt, + SourceLocation StartLoc, + SourceLocation EndLoc); /// Called on well-formed '\#pragma omp parallel sections' after /// parsing of the associated statement. StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef Clauses, diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -1951,6 +1951,7 @@ STMT_OMP_CRITICAL_DIRECTIVE, STMT_OMP_PARALLEL_FOR_DIRECTIVE, STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE, + STMT_OMP_PARALLEL_MASTER_DIRECTIVE, STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE, STMT_OMP_TASK_DIRECTIVE, STMT_OMP_TASKYIELD_DIRECTIVE, diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp --- a/clang/lib/AST/StmtOpenMP.cpp +++ b/clang/lib/AST/StmtOpenMP.cpp @@ -550,6 +550,30 @@ return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses); } +OMPParallelMasterDirective *OMPParallelMasterDirective::Create( + const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, + ArrayRef Clauses, Stmt *AssociatedStmt) { + unsigned Size = + llvm::alignTo(sizeof(OMPParallelMasterDirective), alignof(OMPClause *)); + void *Mem = + C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); + auto *Dir = + new (Mem) OMPParallelMasterDirective(StartLoc, EndLoc, Clauses.size()); + Dir->setClauses(Clauses); + Dir->setAssociatedStmt(AssociatedStmt); + return Dir; +} + +OMPParallelMasterDirective *OMPParallelMasterDirective::CreateEmpty(const ASTContext &C, + unsigned NumClauses, + EmptyShell) { + unsigned Size = + llvm::alignTo(sizeof(OMPParallelMasterDirective), alignof(OMPClause *)); + void *Mem = + C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); + return new (Mem) OMPParallelMasterDirective(NumClauses); +} + OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef Clauses, Stmt *AssociatedStmt, bool HasCancel) { diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -714,6 +714,12 @@ PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPParallelMasterDirective( + OMPParallelMasterDirective *Node) { + Indent() << "#pragma omp parallel master"; + PrintOMPExecutableDirective(Node); +} + void StmtPrinter::VisitOMPParallelSectionsDirective( OMPParallelSectionsDirective *Node) { Indent() << "#pragma omp parallel sections"; diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -833,6 +833,11 @@ VisitOMPLoopDirective(S); } +void StmtProfiler::VisitOMPParallelMasterDirective( + const OMPParallelMasterDirective *S) { + VisitOMPExecutableDirective(S); +} + void StmtProfiler::VisitOMPParallelSectionsDirective( const OMPParallelSectionsDirective *S) { VisitOMPExecutableDirective(S); diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -536,6 +536,16 @@ break; } break; + case OMPD_parallel_master: + switch (CKind) { +#define OPENMP_PARALLEL_MASTER_CLAUSE(Name) \ + case OMPC_##Name: \ + return true; +#include "clang/Basic/OpenMPKinds.def" + default: + break; + } + break; case OMPD_parallel_sections: switch (CKind) { #define OPENMP_PARALLEL_SECTIONS_CLAUSE(Name) \ @@ -1011,6 +1021,7 @@ DKind == OMPD_teams_distribute_parallel_for_simd || DKind == OMPD_target_teams_distribute_parallel_for || DKind == OMPD_target_teams_distribute_parallel_for_simd || + DKind == OMPD_parallel_master || DKind == OMPD_parallel_master_taskloop || DKind == OMPD_parallel_master_taskloop_simd; } @@ -1109,6 +1120,7 @@ case OMPD_parallel: case OMPD_parallel_for: case OMPD_parallel_for_simd: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_distribute_parallel_for: case OMPD_distribute_parallel_for_simd: diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -6674,6 +6674,7 @@ case OMPD_parallel: case OMPD_for: case OMPD_parallel_for: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_for_simd: case OMPD_parallel_for_simd: @@ -6984,6 +6985,7 @@ case OMPD_parallel: case OMPD_for: case OMPD_parallel_for: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_for_simd: case OMPD_parallel_for_simd: @@ -8762,6 +8764,7 @@ case OMPD_parallel: case OMPD_for: case OMPD_parallel_for: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_for_simd: case OMPD_parallel_for_simd: @@ -9523,6 +9526,7 @@ case OMPD_parallel: case OMPD_for: case OMPD_parallel_for: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_for_simd: case OMPD_parallel_for_simd: @@ -10145,6 +10149,7 @@ case OMPD_parallel: case OMPD_for: case OMPD_parallel_for: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_for_simd: case OMPD_parallel_for_simd: diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp @@ -761,6 +761,7 @@ case OMPD_parallel: case OMPD_for: case OMPD_parallel_for: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_for_simd: case OMPD_parallel_for_simd: @@ -836,6 +837,7 @@ case OMPD_parallel: case OMPD_for: case OMPD_parallel_for: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_for_simd: case OMPD_parallel_for_simd: @@ -1004,6 +1006,7 @@ case OMPD_parallel: case OMPD_for: case OMPD_parallel_for: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_for_simd: case OMPD_parallel_for_simd: @@ -1085,6 +1088,7 @@ case OMPD_parallel: case OMPD_for: case OMPD_parallel_for: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_for_simd: case OMPD_parallel_for_simd: diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -221,6 +221,9 @@ case Stmt::OMPParallelForSimdDirectiveClass: EmitOMPParallelForSimdDirective(cast(*S)); break; + case Stmt::OMPParallelMasterDirectiveClass: + EmitOMPParallelMasterDirective(cast(*S)); + break; case Stmt::OMPParallelSectionsDirectiveClass: EmitOMPParallelSectionsDirective(cast(*S)); break; diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -2896,13 +2896,17 @@ } } -void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) { +static void emitMaster(CodeGenFunction &CGF, const OMPExecutableDirective &S) { auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) { Action.Enter(CGF); CGF.EmitStmt(S.getInnermostCapturedStmt()->getCapturedStmt()); }; + CGF.CGM.getOpenMPRuntime().emitMasterRegion(CGF, CodeGen, S.getBeginLoc()); +} + +void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &S) { OMPLexicalScope Scope(*this, S, OMPD_unknown); - CGM.getOpenMPRuntime().emitMasterRegion(*this, CodeGen, S.getBeginLoc()); + emitMaster(*this, S); } void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &S) { @@ -2946,6 +2950,35 @@ emitEmptyBoundParameters); } +void CodeGenFunction::EmitOMPParallelMasterDirective( + const OMPParallelMasterDirective &S) { + // Emit directive as a combined directive that consists of two implicit + // directives: 'parallel' with 'master' directive. + auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &Action) { + Action.Enter(CGF); + OMPPrivateScope PrivateScope(CGF); + bool Copyins = CGF.EmitOMPCopyinClause(S); + (void)CGF.EmitOMPFirstprivateClause(S, PrivateScope); + if (Copyins) { + // Emit implicit barrier to synchronize threads and avoid data races on + // propagation master's thread values of threadprivate variables to local + // instances of that variables of all other implicit threads. + CGF.CGM.getOpenMPRuntime().emitBarrierCall( + CGF, S.getBeginLoc(), OMPD_unknown, /*EmitChecks=*/false, + /*ForceSimpleCall=*/true); + } + CGF.EmitOMPPrivateClause(S, PrivateScope); + CGF.EmitOMPReductionClauseInit(S, PrivateScope); + (void)PrivateScope.Privatize(); + emitMaster(CGF, S); + CGF.EmitOMPReductionClauseFinal(S, /*ReductionKind=*/OMPD_parallel); + }; + emitCommonOMPParallelDirective(*this, S, OMPD_master, CodeGen, + emitEmptyBoundParameters); + emitPostUpdateForReductionClause(*this, S, + [](CodeGenFunction &) { return nullptr; }); +} + void CodeGenFunction::EmitOMPParallelSectionsDirective( const OMPParallelSectionsDirective &S) { // Emit directive as a combined directive that consists of two implicit diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -3145,6 +3145,7 @@ void EmitOMPParallelForDirective(const OMPParallelForDirective &S); void EmitOMPParallelForSimdDirective(const OMPParallelForSimdDirective &S); void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S); + void EmitOMPParallelMasterDirective(const OMPParallelMasterDirective &S); void EmitOMPTaskDirective(const OMPTaskDirective &S); void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S); void EmitOMPBarrierDirective(const OMPBarrierDirective &S); diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -44,7 +44,6 @@ OMPD_target_teams_distribute_parallel, OMPD_mapper, OMPD_variant, - OMPD_parallel_master, }; class DeclDirectiveListParserHelper final { @@ -1558,6 +1557,7 @@ case OMPD_parallel_for: case OMPD_parallel_for_simd: case OMPD_parallel_sections: + case OMPD_parallel_master: case OMPD_atomic: case OMPD_target: case OMPD_teams: @@ -1625,20 +1625,20 @@ /// executable-directive: /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | /// 'section' | 'single' | 'master' | 'critical' [ '(' ')' ] | -/// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | -/// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' | -/// 'for simd' | 'parallel for simd' | 'target' | 'target data' | -/// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | 'master -/// taskloop' | 'master taskloop simd' | 'parallel master taskloop' | -/// 'parallel master taskloop simd' | 'distribute' | 'target enter data' -/// | 'target exit data' | 'target parallel' | 'target parallel for' | -/// 'target update' | 'distribute parallel for' | 'distribute paralle -/// for simd' | 'distribute simd' | 'target parallel for simd' | 'target -/// simd' | 'teams distribute' | 'teams distribute simd' | 'teams -/// distribute parallel for simd' | 'teams distribute parallel for' | -/// 'target teams' | 'target teams distribute' | 'target teams -/// distribute parallel for' | 'target teams distribute parallel for -/// simd' | 'target teams distribute simd' {clause} +/// 'parallel for' | 'parallel sections' | 'parallel master' | 'task' | +/// 'taskyield' | 'barrier' | 'taskwait' | 'flush' | 'ordered' | +/// 'atomic' | 'for simd' | 'parallel for simd' | 'target' | 'target +/// data' | 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | +/// 'master taskloop' | 'master taskloop simd' | 'parallel master +/// taskloop' | 'parallel master taskloop simd' | 'distribute' | 'target +/// enter data' | 'target exit data' | 'target parallel' | 'target +/// parallel for' | 'target update' | 'distribute parallel for' | +/// 'distribute paralle for simd' | 'distribute simd' | 'target parallel +/// for simd' | 'target simd' | 'teams distribute' | 'teams distribute +/// simd' | 'teams distribute parallel for simd' | 'teams distribute +/// parallel for' | 'target teams' | 'target teams distribute' | 'target +/// teams distribute parallel for' | 'target teams distribute parallel +/// for simd' | 'target teams distribute simd' {clause} /// annot_pragma_openmp_end /// StmtResult @@ -1803,6 +1803,7 @@ case OMPD_parallel_for: case OMPD_parallel_for_simd: case OMPD_parallel_sections: + case OMPD_parallel_master: case OMPD_task: case OMPD_ordered: case OMPD_atomic: diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -3248,6 +3248,7 @@ case OMPD_parallel_for: case OMPD_parallel_for_simd: case OMPD_parallel_sections: + case OMPD_parallel_master: case OMPD_teams: case OMPD_teams_distribute: case OMPD_teams_distribute_simd: { @@ -4055,6 +4056,7 @@ NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || isOpenMPTaskingDirective(ParentRegion) || ParentRegion == OMPD_master || + ParentRegion == OMPD_parallel_master || ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; } else if (isOpenMPWorksharingDirective(CurrentRegion) && @@ -4066,6 +4068,7 @@ NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || isOpenMPTaskingDirective(ParentRegion) || ParentRegion == OMPD_master || + ParentRegion == OMPD_parallel_master || ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; Recommend = ShouldBeInParallelRegion; @@ -4541,6 +4544,11 @@ if (LangOpts.OpenMP >= 50) AllowedNameModifiers.push_back(OMPD_simd); break; + case OMPD_parallel_master: + Res = ActOnOpenMPParallelMasterDirective(ClausesWithImplicit, AStmt, + StartLoc, EndLoc); + AllowedNameModifiers.push_back(OMPD_parallel); + break; case OMPD_parallel_sections: Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); @@ -8242,6 +8250,28 @@ } StmtResult +Sema::ActOnOpenMPParallelMasterDirective(ArrayRef Clauses, + Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc) { + if (!AStmt) + return StmtError(); + + assert(isa(AStmt) && "Captured statement expected"); + auto *CS = cast(AStmt); + // 1.2.2 OpenMP Language Terminology + // Structured block - An executable statement with a single entry at the + // top and a single exit at the bottom. + // The point of exit cannot be a branch out of the structured block. + // longjmp() and throw() must not violate the entry/exit criteria. + CS->getCapturedDecl()->setNothrow(); + + setFunctionHasBranchProtectedScope(); + + return OMPParallelMasterDirective::Create(Context, StartLoc, EndLoc, Clauses, + AStmt); +} + +StmtResult Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { @@ -10685,6 +10715,7 @@ break; case OMPD_cancel: case OMPD_parallel: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_parallel_for: case OMPD_target: @@ -10751,6 +10782,7 @@ CaptureRegion = OMPD_teams; break; case OMPD_parallel: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_parallel_for: case OMPD_parallel_for_simd: @@ -10841,6 +10873,7 @@ case OMPD_target_update: case OMPD_cancel: case OMPD_parallel: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_parallel_for: case OMPD_parallel_for_simd: @@ -10912,6 +10945,7 @@ case OMPD_target_update: case OMPD_cancel: case OMPD_parallel: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_parallel_for: case OMPD_parallel_for_simd: @@ -10991,6 +11025,7 @@ case OMPD_target_parallel: case OMPD_cancel: case OMPD_parallel: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_threadprivate: case OMPD_allocate: @@ -11062,6 +11097,7 @@ case OMPD_target_parallel: case OMPD_cancel: case OMPD_parallel: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_threadprivate: case OMPD_allocate: @@ -11130,6 +11166,7 @@ case OMPD_parallel_master_taskloop_simd: case OMPD_cancel: case OMPD_parallel: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_parallel_for: case OMPD_parallel_for_simd: @@ -11203,6 +11240,7 @@ case OMPD_distribute_parallel_for_simd: case OMPD_cancel: case OMPD_parallel: + case OMPD_parallel_master: case OMPD_parallel_sections: case OMPD_parallel_for: case OMPD_parallel_for_simd: diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -8044,6 +8044,17 @@ } template +StmtResult TreeTransform::TransformOMPParallelMasterDirective( + OMPParallelMasterDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_master, DirName, + nullptr, D->getBeginLoc()); + StmtResult Res = getDerived().TransformOMPExecutableDirective(D); + getDerived().getSema().EndOpenMPDSABlock(Res.get()); + return Res; +} + +template StmtResult TreeTransform::TransformOMPParallelSectionsDirective( OMPParallelSectionsDirective *D) { DeclarationNameInfo DirName; diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -2165,6 +2165,14 @@ VisitOMPLoopDirective(D); } +void ASTStmtReader::VisitOMPParallelMasterDirective( + OMPParallelMasterDirective *D) { + VisitStmt(D); + // The NumClauses field was read in ReadStmtFromStream. + Record.skipInts(1); + VisitOMPExecutableDirective(D); +} + void ASTStmtReader::VisitOMPParallelSectionsDirective( OMPParallelSectionsDirective *D) { VisitStmt(D); @@ -3003,6 +3011,11 @@ break; } + case STMT_OMP_PARALLEL_MASTER_DIRECTIVE: + S = OMPParallelMasterDirective::CreateEmpty( + Context, Record[ASTStmtReader::NumStmtFields], Empty); + break; + case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE: S = OMPParallelSectionsDirective::CreateEmpty( Context, Record[ASTStmtReader::NumStmtFields], Empty); diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -2103,6 +2103,14 @@ Code = serialization::STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE; } +void ASTStmtWriter::VisitOMPParallelMasterDirective( + OMPParallelMasterDirective *D) { + VisitStmt(D); + Record.push_back(D->getNumClauses()); + VisitOMPExecutableDirective(D); + Code = serialization::STMT_OMP_PARALLEL_MASTER_DIRECTIVE; +} + void ASTStmtWriter::VisitOMPParallelSectionsDirective( OMPParallelSectionsDirective *D) { VisitStmt(D); diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1246,6 +1246,7 @@ case Stmt::OMPParallelForDirectiveClass: case Stmt::OMPParallelForSimdDirectiveClass: case Stmt::OMPParallelSectionsDirectiveClass: + case Stmt::OMPParallelMasterDirectiveClass: case Stmt::OMPTaskDirectiveClass: case Stmt::OMPTaskyieldDirectiveClass: case Stmt::OMPBarrierDirectiveClass: diff --git a/clang/test/OpenMP/nesting_of_regions.cpp b/clang/test/OpenMP/nesting_of_regions.cpp --- a/clang/test/OpenMP/nesting_of_regions.cpp +++ b/clang/test/OpenMP/nesting_of_regions.cpp @@ -61,6 +61,11 @@ bar(); } #pragma omp parallel +#pragma omp parallel master + { + bar(); + } +#pragma omp parallel #pragma omp task { bar(); @@ -301,6 +306,13 @@ } #pragma omp simd for (int i = 0; i < 10; ++i) { +#pragma omp parallel master // expected-error {{OpenMP constructs may not be nested inside a simd region}} + { + bar(); + } + } +#pragma omp simd + for (int i = 0; i < 10; ++i) { #pragma omp task // expected-error {{OpenMP constructs may not be nested inside a simd region}} { bar(); @@ -563,6 +575,13 @@ } #pragma omp for for (int i = 0; i < 10; ++i) { +#pragma omp parallel master + { + bar(); + } + } +#pragma omp for + for (int i = 0; i < 10; ++i) { #pragma omp parallel sections { bar(); @@ -809,6 +828,13 @@ } #pragma omp for simd for (int i = 0; i < 10; ++i) { +#pragma omp parallel master // expected-error {{OpenMP constructs may not be nested inside a simd region}} + { + bar(); + } + } +#pragma omp for simd + for (int i = 0; i < 10; ++i) { #pragma omp parallel sections // expected-error {{OpenMP constructs may not be nested inside a simd region}} { bar(); @@ -1045,6 +1071,13 @@ } #pragma omp sections { +#pragma omp parallel master + { + bar(); + } + } +#pragma omp sections + { #pragma omp parallel { #pragma omp master // OK @@ -1321,6 +1354,16 @@ { #pragma omp section { +#pragma omp parallel master + bar(); +#pragma omp critical + bar(); + } + } +#pragma omp sections + { +#pragma omp section + { #pragma omp single // expected-error {{region cannot be closely nested inside 'section' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} bar(); #pragma omp master // expected-error {{region cannot be closely nested inside 'section' region}} @@ -1633,6 +1676,13 @@ } #pragma omp single { +#pragma omp parallel master + { + bar(); + } + } +#pragma omp single + { #pragma omp critical { bar(); @@ -1922,6 +1972,26 @@ } #pragma omp master { +#pragma omp parallel master // OK + { + bar(); + } +#pragma omp parallel + { +#pragma omp for // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp for simd // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp sections // OK + { + bar(); + } + } + } +#pragma omp master + { #pragma omp parallel for for (int i = 0; i < 10; ++i) ; @@ -2177,6 +2247,13 @@ } #pragma omp critical { +#pragma omp parallel master + { + bar(); + } + } +#pragma omp critical + { #pragma omp parallel for for (int i = 0; i < 10; ++i) ; @@ -2910,6 +2987,281 @@ ; } +// PARALLEL MASTER DIRECTIVE +#pragma omp parallel master + { +#pragma omp for // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp for simd // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp for simd' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp parallel + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp single // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp parallel master + { +#pragma omp master // OK, though second 'master' is redundant + { + bar(); + } + } +#pragma omp parallel master + { +#pragma omp critical + { + bar(); + } + } +#pragma omp parallel master + { +#pragma omp sections // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp parallel master + { +#pragma omp parallel + { +#pragma omp parallel master // OK + { + bar(); + } +#pragma omp for // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp for simd // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp sections // OK + { + bar(); + } + } + } +#pragma omp parallel master + { +#pragma omp parallel master // OK + { + bar(); + } +#pragma omp parallel + { +#pragma omp for // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp for simd // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp sections // OK + { + bar(); + } + } + } +#pragma omp parallel master + { +#pragma omp parallel for + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp parallel sections + { + bar(); + } + } +#pragma omp parallel master + { +#pragma omp task + { + bar(); + } + } +#pragma omp parallel master + { +#pragma omp taskyield + bar(); + } +#pragma omp parallel master + { +#pragma omp barrier // expected-error {{region cannot be closely nested inside 'parallel master' region}} + bar(); + } +#pragma omp parallel master + { +#pragma omp taskwait + bar(); + } +#pragma omp parallel master + { +#pragma omp flush + bar(); + } +#pragma omp parallel master + { +#pragma omp ordered // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + bar(); + } +#pragma omp parallel master + { +#pragma omp atomic + ++a; + } +#pragma omp parallel master + { +#pragma omp target + ++a; + } +#pragma omp parallel master + { +#pragma omp target parallel + ++a; + } +#pragma omp parallel master + { +#pragma omp target parallel for + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp target enter data map(to: a) + ++a; + } +#pragma omp parallel master + { +#pragma omp target exit data map(from: a) + ++a; + } +#pragma omp parallel master + { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } +#pragma omp parallel master + { +#pragma omp taskloop + for (int i = 0; i < 10; ++i) + ++a; + } +#pragma omp parallel master + { +#pragma omp distribute // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp distribute' directive into a teams region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp target update to(a) + bar(); + } +#pragma omp parallel master + { +#pragma omp distribute parallel for // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp distribute parallel for' directive into a teams region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp distribute parallel for simd // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp distribute parallel for simd' directive into a teams region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp distribute simd // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp distribute simd' directive into a teams region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp target simd // OK + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp teams distribute // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp teams distribute' directive into a target region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp teams distribute simd // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp teams distribute simd' directive into a target region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp teams distribute parallel for simd // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp teams distribute parallel for simd' directive into a target region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp teams distribute parallel for // expected-error {{region cannot be closely nested inside 'parallel master' region; perhaps you forget to enclose 'omp teams distribute parallel for' directive into a target region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp target teams // OK + a++; + } +#pragma omp parallel master + { +#pragma omp target teams distribute // OK + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp target teams distribute parallel for // OK + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp target teams distribute parallel for simd // OK + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp parallel master + { +#pragma omp target teams distribute simd // OK + for (int i = 0; i < 10; ++i) + ; + } + // PARALLEL SECTIONS DIRECTIVE #pragma omp parallel sections { @@ -3722,6 +4074,15 @@ // 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 parallel master // expected-error {{OpenMP constructs may not be nested inside an atomic region}} + { + bar(); + } + } +#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 critical // expected-error {{OpenMP constructs may not be nested inside an atomic region}} { bar(); @@ -4237,6 +4598,11 @@ { bar(); } +#pragma omp target +#pragma omp parallel master + { + bar(); + } #pragma omp target parallel #pragma omp critical { @@ -9000,6 +9366,8 @@ #pragma omp parallel #pragma omp master bar(); +#pragma omp parallel master + bar(); #pragma omp parallel #pragma omp critical bar(); @@ -10760,6 +11128,11 @@ for (int i = 0; i < 10; ++i) ; } +#pragma omp parallel master + { + for (int i = 0; i < 10; ++i) + ; + } #pragma omp master { #pragma omp single // expected-error {{region cannot be closely nested inside 'master' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} @@ -10810,6 +11183,13 @@ } #pragma omp master { +#pragma omp parallel master + { + bar(); + } + } +#pragma omp master + { #pragma omp parallel for for (int i = 0; i < 10; ++i) ; diff --git a/clang/test/OpenMP/parallel_master_ast_print.cpp b/clang/test/OpenMP/parallel_master_ast_print.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_ast_print.cpp @@ -0,0 +1,222 @@ +// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -ast-print %s | FileCheck %s +// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s + +// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 -ast-print %s | FileCheck %s +// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +void foo() {} + +struct S1 { + S1(): a(0) {} + S1(int v) : a(v) {} + int a; + typedef int type; + S1& operator +(const S1&); + S1& operator *(const S1&); + S1& operator &&(const S1&); + S1& operator ^(const S1&); +}; + +template +class S7 : public T { +protected: + T a; + T b[100]; + S7() : a(0) {} + +public: + S7(typename T::type v) : a(v) { +#pragma omp parallel master private(a) private(this->a) private(T::a) + for (int k = 0; k < a.a; ++k) + ++this->a.a; +#pragma omp parallel master firstprivate(a) firstprivate(this->a) firstprivate(T::a) + for (int k = 0; k < a.a; ++k) + ++this->a.a; +#pragma omp parallel master shared(a) shared(this->a) shared(T::a) + for (int k = 0; k < a.a; ++k) + ++this->a.a; +#pragma omp parallel master reduction(+ : a) reduction(*: b[:]) + for (int k = 0; k < a.a; ++k) + ++this->a.a; + } + S7 &operator=(S7 &s) { +#pragma omp parallel master private(a) private(this->a) + for (int k = 0; k < s.a.a; ++k) + ++s.a.a; +#pragma omp parallel master firstprivate(a) firstprivate(this->a) + for (int k = 0; k < s.a.a; ++k) + ++s.a.a; +#pragma omp parallel master shared(a) shared(this->a) + for (int k = 0; k < s.a.a; ++k) + ++s.a.a; +#pragma omp parallel master reduction(&& : this->a) reduction(^: b[s.a.a]) + for (int k = 0; k < s.a.a; ++k) + ++s.a.a; + return *this; + } +}; + +// CHECK: #pragma omp parallel master private(this->a) private(this->a) private(T::a) +// CHECK: #pragma omp parallel master firstprivate(this->a) firstprivate(this->a) firstprivate(T::a) +// CHECK: #pragma omp parallel master shared(this->a) shared(this->a) shared(T::a) +// CHECK: #pragma omp parallel master reduction(+: this->a) reduction(*: this->b[:]) +// CHECK: #pragma omp parallel master private(this->a) private(this->a) +// CHECK: #pragma omp parallel master firstprivate(this->a) firstprivate(this->a) +// CHECK: #pragma omp parallel master shared(this->a) shared(this->a) +// CHECK: #pragma omp parallel master reduction(&&: this->a) reduction(^: this->b[s.a.a]) +// CHECK: #pragma omp parallel master private(this->a) private(this->a) private(this->S1::a) +// CHECK: #pragma omp parallel master firstprivate(this->a) firstprivate(this->a) firstprivate(this->S1::a) +// CHECK: #pragma omp parallel master shared(this->a) shared(this->a) shared(this->S1::a) +// CHECK: #pragma omp parallel master reduction(+: this->a) reduction(*: this->b[:]) + +class S8 : public S7 { + S8() {} + +public: + S8(int v) : S7(v){ +#pragma omp parallel master private(a) private(this->a) private(S7 < S1 > ::a) + for (int k = 0; k < a.a; ++k) + ++this->a.a; +#pragma omp parallel master firstprivate(a) firstprivate(this->a) firstprivate(S7 < S1 > ::a) + for (int k = 0; k < a.a; ++k) + ++this->a.a; +#pragma omp parallel master shared(a) shared(this->a) shared(S7 < S1 > ::a) + for (int k = 0; k < a.a; ++k) + ++this->a.a; +#pragma omp parallel master reduction(^ : S7 < S1 > ::a) reduction(+ : S7 < S1 > ::b[ : S7 < S1 > ::a.a]) + for (int k = 0; k < a.a; ++k) + ++this->a.a; + } + S8 &operator=(S8 &s) { +#pragma omp parallel master private(a) private(this->a) + for (int k = 0; k < s.a.a; ++k) + ++s.a.a; +#pragma omp parallel master firstprivate(a) firstprivate(this->a) + for (int k = 0; k < s.a.a; ++k) + ++s.a.a; +#pragma omp parallel master shared(a) shared(this->a) + for (int k = 0; k < s.a.a; ++k) + ++s.a.a; +#pragma omp parallel master reduction(* : this->a) reduction(&&:this->b[a.a:]) + for (int k = 0; k < s.a.a; ++k) + ++s.a.a; + return *this; + } +}; + +// CHECK: #pragma omp parallel master private(this->a) private(this->a) private(this->S7::a) +// CHECK: #pragma omp parallel master firstprivate(this->a) firstprivate(this->a) firstprivate(this->S7::a) +// CHECK: #pragma omp parallel master shared(this->a) shared(this->a) shared(this->S7::a) +// CHECK: #pragma omp parallel master reduction(^: this->S7::a) reduction(+: this->S7::b[:this->S7::a.a]) +// CHECK: #pragma omp parallel master private(this->a) private(this->a) +// CHECK: #pragma omp parallel master firstprivate(this->a) firstprivate(this->a) +// CHECK: #pragma omp parallel master shared(this->a) shared(this->a) +// CHECK: #pragma omp parallel master reduction(*: this->a) reduction(&&: this->b[this->a.a:]) + +template +struct S { + operator T() {return T();} + static T TS; + #pragma omp threadprivate(TS) +}; + +// CHECK: template struct S { +// CHECK: static T TS; +// CHECK-NEXT: #pragma omp threadprivate(S::TS) +// CHECK: }; +// CHECK: template<> struct S { +// CHECK: static int TS; +// CHECK-NEXT: #pragma omp threadprivate(S::TS) +// CHECK-NEXT: } +// CHECK: template<> struct S { +// CHECK: static long TS; +// CHECK-NEXT: #pragma omp threadprivate(S::TS) +// CHECK-NEXT: } + +int thrp; +#pragma omp threadprivate(thrp) + +template +T tmain(T argc, T *argv) { + T b = argc, c, d, e, f, g; + static T a; + S s; + T arr[C][10], arr1[C]; +#pragma omp parallel master + a=2; +#pragma omp parallel master default(none), private(argc,b) firstprivate(argv) shared (d) if (parallel:argc > 0) num_threads(C) copyin(S::TS, thrp) proc_bind(master) reduction(+:c, arr1[argc]) reduction(max:e, arr[:C][0:10]) + foo(); +#pragma omp parallel master if (C) num_threads(s) proc_bind(close) reduction(^:e, f, arr[0:C][:argc]) reduction(&& : g) + foo(); + return 0; +} + +// CHECK: template T tmain(T argc, T *argv) { +// CHECK-NEXT: T b = argc, c, d, e, f, g; +// CHECK-NEXT: static T a; +// CHECK-NEXT: S s; +// CHECK-NEXT: T arr[C][10], arr1[C]; +// CHECK-NEXT: #pragma omp parallel master{{$}} +// CHECK-NEXT: a = 2; +// CHECK-NEXT: #pragma omp parallel master default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(C) copyin(S::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:C][0:10]) +// CHECK-NEXT: foo() +// CHECK-NEXT: #pragma omp parallel master if(C) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:C][:argc]) reduction(&&: g) +// CHECK-NEXT: foo() +// CHECK: template<> int tmain(int argc, int *argv) { +// CHECK-NEXT: int b = argc, c, d, e, f, g; +// CHECK-NEXT: static int a; +// CHECK-NEXT: S s; +// CHECK-NEXT: int arr[5][10], arr1[5]; +// CHECK-NEXT: #pragma omp parallel master +// CHECK-NEXT: a = 2; +// CHECK-NEXT: #pragma omp parallel master default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(5) copyin(S::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:5][0:10]) +// CHECK-NEXT: foo() +// CHECK-NEXT: #pragma omp parallel master if(5) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:5][:argc]) reduction(&&: g) +// CHECK-NEXT: foo() +// CHECK: template<> long tmain(long argc, long *argv) { +// CHECK-NEXT: long b = argc, c, d, e, f, g; +// CHECK-NEXT: static long a; +// CHECK-NEXT: S s; +// CHECK-NEXT: long arr[1][10], arr1[1]; +// CHECK-NEXT: #pragma omp parallel master +// CHECK-NEXT: a = 2; +// CHECK-NEXT: #pragma omp parallel master default(none) private(argc,b) firstprivate(argv) shared(d) if(parallel: argc > 0) num_threads(1) copyin(S::TS,thrp) proc_bind(master) reduction(+: c,arr1[argc]) reduction(max: e,arr[:1][0:10]) +// CHECK-NEXT: foo() +// CHECK-NEXT: #pragma omp parallel master if(1) num_threads(s) proc_bind(close) reduction(^: e,f,arr[0:1][:argc]) reduction(&&: g) +// CHECK-NEXT: foo() + +enum Enum { }; + +int main (int argc, char **argv) { + long x; + int b = argc, c, d, e, f, g; + static int a; + #pragma omp threadprivate(a) + int arr[10][argc], arr1[2]; + Enum ee; +// CHECK: Enum ee; +#pragma omp parallel master +// CHECK-NEXT: #pragma omp parallel master + a=2; +// CHECK-NEXT: a = 2; +#pragma omp parallel master default(none), private(argc,b) firstprivate(argv) if (parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(| : c, d, arr1[argc]) reduction(* : e, arr[:10][0:argc]) allocate(e) +// CHECK-NEXT: #pragma omp parallel master default(none) private(argc,b) firstprivate(argv) if(parallel: argc > 0) num_threads(ee) copyin(a) proc_bind(spread) reduction(|: c,d,arr1[argc]) reduction(*: e,arr[:10][0:argc]) allocate(e) + foo(); +// CHECK-NEXT: foo(); +// CHECK-NEXT: #pragma omp parallel master allocate(e) if(b) num_threads(c) proc_bind(close) reduction(^: e,f) reduction(&&: g,arr[0:argc][:10]) +// CHECK-NEXT: foo() +#pragma omp parallel master allocate(e) if (b) num_threads(c) proc_bind(close) reduction(^:e, f) reduction(&& : g, arr[0:argc][:10]) + foo(); + return tmain(b, &b) + tmain(x, &x); +} + +template +T S::TS = 0; + +#endif diff --git a/clang/test/OpenMP/parallel_master_codegen.cpp b/clang/test/OpenMP/parallel_master_codegen.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_codegen.cpp @@ -0,0 +1,471 @@ +// expected-no-diagnostics +#ifndef HEADER +#define HEADER + +#ifdef CK1 +///==========================================================================/// +// RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK1 +// RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK1 + +// RUN: %clang_cc1 -DCK1 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// RUN: %clang_cc1 -DCK1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// SIMD-ONLY0-NOT: {{__kmpc|__tgt}} + +// CK1-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// CK1-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" +// CK1-DAG: [[DEF_LOC:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } + +// CK1-LABEL: foo +void foo() {} + +void parallel_master() { +#pragma omp parallel master + foo(); +} + +// CK1-LABEL: define void @{{.+}}parallel_master{{.+}} +// CK1: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*)) + +// CK1: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias %.global_tid., i32* noalias %.bound_tid.) +// CK1-NOT: __kmpc_global_thread_num +// CK1: call i32 @__kmpc_master({{.+}}) +// CK1: invoke void {{.*}}foo{{.*}}() +// CK1-NOT: __kmpc_global_thread_num +// CK1: call void @__kmpc_end_master({{.+}}) +// CK1: call void @__clang_call_terminate +// CK1: unreachable + +#endif + +#ifdef CK2 +///==========================================================================/// +// RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK2 +// RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK2 + +// RUN: %clang_cc1 -DCK2 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// RUN: %clang_cc1 -DCK2 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK2 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// SIMD-ONLY0-NOT: {{__kmpc|__tgt}} + +// CK2-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// CK2-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" +// CK2-DAG: [[DEF_LOC:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } + +void parallel_master_private() { + int a; +#pragma omp parallel master private(a) + a++; +} + +// CK2-LABEL: define void @{{.+}}parallel_master_private{{.+}} +// CK2: [[A_PRIV:%.+]] = alloca i32 +// CK2: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*)) + +// CK2: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias %.global_tid., i32* noalias %.bound_tid.) +// CK2-NOT: __kmpc_global_thread_num +// CK2: call i32 @__kmpc_master({{.+}}) +// CK2: [[A_VAL:%.+]] = load i32, i32* [[A_PRIV]] +// CK2: [[INC:%.+]] = add nsw i32 [[A_VAL]] +// CK2: store i32 [[INC]], i32* [[A_PRIV]] +// CK2-NOT: __kmpc_global_thread_num +// CK2: call void @__kmpc_end_master({{.+}}) +// CK2: ret void + +#endif + +#ifdef CK3 +///==========================================================================/// +// RUN: %clang_cc1 -DCK3 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK3 +// RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK3 + +// RUN: %clang_cc1 -DCK3 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// RUN: %clang_cc1 -DCK3 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK3 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// SIMD-ONLY0-NOT: {{__kmpc|__tgt}} + +// CK3-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// CK3-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" + +void parallel_master_private() { + int a; +#pragma omp parallel master default(shared) + a++; +} + +// CK3-LABEL: define void @{{.+}}parallel_master{{.+}} +// CK3: [[A_VAL:%.+]] = alloca i32 +// CK3: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* {{.+}}, i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OMP_OUTLINED:@.+]] to void + +// CK3: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias %.global_tid., i32* noalias %.bound_tid., i32* dereferenceable(4) [[A_VAL]]) +// CK3: %.global_tid..addr = alloca i32* +// CK3: %.bound_tid..addr = alloca i32* +// CK3: [[A_ADDR:%.+]] = alloca i32* +// CK3: store i32* %.global_tid., i32** %.global_tid..addr +// CK3: store i32* %.bound_tid., i32** %.bound_tid..addr +// CK3: store i32* [[A_VAL]], i32** [[A_ADDR]] +// CK3: [[ZERO:%.+]] = load i32*, i32** [[A_ADDR]] +// CK3-NOT: __kmpc_global_thread_num +// CK3: call i32 @__kmpc_master({{.+}}) +// CK3: [[FIVE:%.+]] = load i32, i32* [[ZERO]] +// CK3: [[INC:%.+]] = add nsw i32 [[FIVE]] +// CK3: store i32 [[INC]], i32* [[ZERO]] +// CK3-NOT: __kmpc_global_thread_num +// CK3: call void @__kmpc_end_master({{.+}}) + +#endif + +#ifdef CK4 +///==========================================================================/// +// RUN: %clang_cc1 -DCK4 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK4 +// RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK4 + +// RUN: %clang_cc1 -DCK4 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// RUN: %clang_cc1 -DCK4 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK4 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// SIMD-ONLY0-NOT: {{__kmpc|__tgt}} + +// CK4-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// CK4-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" +// CK4-DAG: [[DEF_LOC:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } + +void parallel_master_firstprivate() { + int a; +#pragma omp parallel master firstprivate(a) + a++; +} + +// CK4-LABEL: define void @{{.+}}parallel_master_firstprivate{{.+}} +// CK4: [[A_VAL:%.+]] = alloca i32 +// CK4: [[A_CASTED:%.+]] = alloca i64 +// CK4: [[ZERO:%.+]] = load i32, i32* [[A_VAL]] +// CK4: [[CONV:%.+]] = bitcast i64* [[A_CASTED]] to i32* +// CK4: store i32 [[ZERO]], i32* [[CONV]] +// CK4: [[ONE:%.+]] = load i64, i64* [[A_CASTED]] +// CK4: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i64)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*), i64 [[ONE]]) + +// CK4: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]], i64 [[A_VAL]]) +// CK4: [[GLOBAL_TID_ADDR:%.+]] = alloca i32* +// CK4: [[BOUND_TID_ADDR:%.+]] = alloca i32* +// CK4: [[A_ADDR:%.+]] = alloca i64 +// CK4: store i32* [[GLOBAL_TID]], i32** [[GLOBAL_TID_ADDR]] +// CK4: store i32* [[BOUND_TID]], i32** [[BOUND_TID_ADDR]] +// CK4: store i64 [[A_VAL]], i64* [[A_ADDR]] +// CK4: [[CONV]] = bitcast i64* [[A_ADDR]] to i32* +// CK4-NOT: __kmpc_global_thread_num +// CK4: call i32 @__kmpc_master({{.+}}) +// CK4: [[FOUR:%.+]] = load i32, i32* [[CONV]] +// CK4: [[INC:%.+]] = add nsw i32 [[FOUR]] +// CK4: store i32 [[INC]], i32* [[CONV]] +// CK4-NOT: __kmpc_global_thread_num +// CK4: call void @__kmpc_end_master({{.+}}) + +#endif + +#ifdef CK5 +///==========================================================================/// +// RUN: %clang_cc1 -DCK5 -verify -fopenmp -fopenmp -fnoopenmp-use-tls -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK5 +// RUN: %clang_cc1 -DCK5 -fopenmp -fopenmp -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK5 -fopenmp -fopenmp -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK5 + +// RUN: %clang_cc1 -DCK5 -verify -fopenmp-simd -fnoopenmp-use-tls -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// RUN: %clang_cc1 -DCK5 -fopenmp-simd -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK5 -fopenmp-simd -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// SIMD-ONLY0-NOT: {{__kmpc|__tgt}} + +// RUN: %clang_cc1 -DCK5 -verify -fopenmp -x c++ -triple x86_64-linux -emit-llvm %s -o - | FileCheck %s -check-prefix=TLS-CHECK +// RUN: %clang_cc1 -DCK5 -fopenmp -x c++ -std=c++11 -triple x86_64-linux -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK5 -fopenmp -x c++ -triple x86_64-linux -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefix=TLS-CHECK + +// RUN: %clang_cc1 -DCK5 -verify -fopenmp-simd -x c++ -triple x86_64-linux -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY1 %s +// RUN: %clang_cc1 -DCK5 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-linux -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK5 -fopenmp-simd -x c++ -triple x86_64-linux -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s +// SIMD-ONLY1-NOT: {{__kmpc|__tgt}} + +// CK5-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// CK5-DAG: [[A:@.+]] = {{.+}} i32 0 +// CK5-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" +// CK5-DAG: [[DEF_LOC_1:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } +// CK5-DAG: [[A_CACHE:@.+]] = common global i8** null +// CK5-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 66, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } +// TLS-CHECK-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// TLS-CHECK-DAG: [[A:@.+]] = thread_local global i32 0 +// TLS-CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" +// TLS-CHECK-DAG: [[DEF_LOC_1:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 66, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } +// TLS-CHECK-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } + +int a; +#pragma omp threadprivate(a) + +void parallel_master_copyin() { +#pragma omp parallel master copyin(a) + a++; +} + +// CK5-LABEL: define void @{{.+}}parallel_master_copyin{{.+}} +// CK5: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_1]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*)) +// CK5: ret void +// TLS-CHECK-LABEL: define void @{{.+}}parallel_master_copyin{{.+}} +// TLS-CHECK: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*) +// TLS-CHECK: ret void + +// CK5: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]]) +// CK5: [[GLOBAL_TID_ADDR:%.+]] = alloca i32* +// CK5: [[BOUND_TID_ADDR:%.+]] = alloca i32* +// CK5: store i32* [[GLOBAL_TID]], i32** [[GLOBAL_TID_ADDR]] +// CK5: store i32* [[BOUND_TID]], i32** [[BOUND_TID_ADDR]] +// CK5: [[ZERO:%.+]] = load i32*, i32** [[GLOBAL_TID_ADDR]] +// CK5: [[ONE:%.+]] = load i32, i32* [[ZERO]] +// CK5: [[TWO:%.+]] = call i8* @__kmpc_threadprivate_cached(%struct.ident_t* [[DEF_LOC_1]], i32 [[ONE]], i8* bitcast (i32* [[A]] to i8*), i64 4, i8*** [[A_CACHE]]) +// CK5: [[THREE:%.+]] = bitcast i8* [[TWO]] to i32* +// CK5: [[FOUR:%.+]] = ptrtoint i32* [[THREE]] to i64 +// CK5: [[FIVE:%.+]] = icmp ne i64 ptrtoint (i32* [[A]] to i64), [[FOUR]] +// CK5: br i1 [[FIVE]], label [[COPYIN_NOT_MASTER:%.+]], label [[COPYIN_NOT_MASTER_END:%.+]] +// TLS-CHECK: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]], i32* {{.+}} [[A_VAR:%.+]]) +// TLS-CHECK: [[GLOBAL_TID_ADDR:%.+]] = alloca i32* +// TLS-CHECK: [[BOUND_TID_ADDR:%.+]] = alloca i32* +// TLS-CHECK: [[A_ADDR:%.+]] = alloca i32* +// TLS-CHECK: store i32* [[A_VAR]], i32** [[A_ADDR]] +// TLS-CHECK: [[ZERO:%.+]] = load i32*, i32** [[A_ADDR]] +// TLS-CHECK: [[ONE:%.+]] = ptrtoint i32* [[ZERO]] to i64 +// TLS-CHECK: [[TWO:%.+]] = icmp ne i64 [[ONE]], ptrtoint (i32* [[A]] to i64) +// TLS-CHECK: br i1 [[TWO]], label [[COPYIN_NOT_MASTER:%.+]], label [[COPYIN_NOT_MASTER_END:%.+]] + +// CK5-DAG: [[COPYIN_NOT_MASTER]] +// CK5-DAG: [[SIX:%.+]] = load i32, i32* [[A]] +// TLS-CHECK-DAG: [[COPYIN_NOT_MASTER]] +// TLS-CHECK-DAG: [[THREE:%.+]] = load i32, i32* [[ZERO]] +// TLS-CHECK-DAG: store i32 [[THREE]], i32* [[A]] + +// CK5-DAG: [[COPYIN_NOT_MASTER_END]] +// CK5-DAG: call void @__kmpc_barrier(%struct.ident_t* [[DEF_LOC_2]], i32 [[ONE]]) +// CK5-DAG: [[SEVEN:%.+]] = call i32 @__kmpc_master(%struct.ident_t* [[DEF_LOC_1]], i32 [[ONE]]) +// CK5-DAG: [[EIGHT:%.+]] = icmp ne i32 [[SEVEN]], 0 +// CK5-DAG: br i1 %8, label [[OMP_IF_THEN:%.+]], label [[OMP_IF_END:%.+]] +// TLS-CHECK-DAG: [[FOUR:%.+]] = load i32*, i32** [[GLOBAL_TID_ADDR:%.+]] +// TLS-CHECK-DAG: [[FIVE:%.+]] = load i32, i32* [[FOUR]] +// TLS-CHECK-DAG: call void @__kmpc_barrier(%struct.ident_t* [[DEF_LOC_1]], i32 [[FIVE]]) +// TLS-CHECK-DAG: [[SIX:%.+]] = load i32*, i32** [[GLOBAL_TID_ADDR]] +// TLS-CHECK-DAG: [[SEVEN:%.+]] = load i32, i32* [[SIX]] +// TLS-CHECK-DAG: [[EIGHT:%.+]] = call i32 @__kmpc_master(%struct.ident_t* [[DEF_LOC_2]], i32 [[SEVEN]]) +// TLS-CHECK-DAG: [[NINE:%.+]] = icmp ne i32 [[EIGHT]], 0 +// TLS-CHECK-DAG: br i1 [[NINE]], label [[OMP_IF_THEN:%.+]], label [[OMP_IF_END:%.+]] + +// CK5-DAG: [[OMP_IF_THEN]] +// CK5-DAG: [[NINE:%.+]] = call i8* @__kmpc_threadprivate_cached(%struct.ident_t* [[DEF_LOC_1]], i32 %1, i8* bitcast (i32* [[A]] to i8*), i64 4, i8*** [[A_CACHE]]) +// CK5-DAG: [[TEN:%.+]] = bitcast i8* [[NINE]] to i32* +// CK5-DAG: [[ELEVEN:%.+]] = load i32, i32* [[TEN]] +// CK5-DAG: [[INC:%.+]] = add nsw i32 [[ELEVEN]], 1 +// CK5-DAG: store i32 [[INC]], i32* [[TEN]] +// CK5-DAG: call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_1]], i32 [[ONE]]) +// CK5-DAG: [[OMP_IF_END]] +// CK5-DAG: ret void + +// TLS-CHECK-DAG: [[OMP_IF_THEN]] +// TLS-CHECK-DAG: [[TEN:%.+]] = load i32, i32* [[A]] +// TLC-CHECK-DAG: %inc = add nsw i32 [[TEN]], 1 +// TLS-CHECK-DAG: store i32 %inc, i32* [[A]] +// TLS-CHECK-DAG: call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_2]], i32 [[SEVEN]]) +// TLS-CHECK-DAG: [[OMP_IF_END]] +// TLS-CHECK-DAG: ret void + +#endif +#ifdef CK6 +///==========================================================================/// +// RUN: %clang_cc1 -DCK6 -verify -fopenmp -x c++ -triple x86_64-linux -emit-llvm %s -o - | FileCheck %s -check-prefix=CK6 +// RUN: %clang_cc1 -DCK6 -fopenmp -x c++ -std=c++11 -triple x86_64-linux -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK6 -fopenmp -x c++ -triple x86_64-linux -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefix=CK6 + +// RUN: %clang_cc1 -DCK6 -verify -fopenmp-simd -x c++ -triple x86_64-linux -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY1 %s +// RUN: %clang_cc1 -DCK6 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-linux -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK6 -fopenmp-simd -x c++ -triple x86_64-linux -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s +// SIMD-ONLY1-NOT: {{__kmpc|__tgt}} + +// CK6-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// CK6-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" +// CK6-DAG: [[DEF_LOC_1:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } +// CK6-DAG: [[GOMP:@.+]] = common global [8 x i32] zeroinitializer +// CK6-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 18, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } + +void parallel_master_reduction() { + int g; +#pragma omp parallel master reduction(+:g) + g = 1; +} + +// CK6-LABEL: define void @{{.+}}parallel_master_reduction{{.+}} +// CK6: [[G_VAR:%.+]] = alloca i32 +// CK6: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_1]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*), i32* [[G_VAR]]) +// CK6: ret void + +// CK6: define internal void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]], i32* {{.+}} [[G_VAR]]) +// CK6: %.global_tid..addr = alloca i32* +// CK6: %.bound_tid..addr = alloca i32* +// CK6: [[G_ADDR:%.+]] = alloca i32* +// CK6: [[G_1:%.+]] = alloca i32 +// CK6: [[RED_LIST:%.+]] = alloca [1 x i8*] +// CK6: [[ZERO:%.+]] = load i32*, i32** [[G_ADDR]] +// CK6: [[ONE:%.+]] = load i32*, i32** %.global_tid..addr +// CK6: [[TWO:%.+]] = load i32, i32* [[ONE]] +// CK6: [[THREE:%.+]] = call i32 @__kmpc_master(%struct.ident_t* [[DEF_LOC_1]], i32 [[TWO]]) +// CK6: [[FOUR:%.+]] = icmp ne i32 [[THREE]] + +// CK6: store i32 1, i32* [[G_1]] +// CK6: call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_1]], i32 [[TWO]]) + +// CK6: [[FIVE:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[RED_LIST]], i64 0, i64 0 +// CK6: [[SEVEN:%.+]] = bitcast [1 x i8*]* [[RED_LIST]] to i8* +// CK6: [[EIGHT:%.+]] = call i32 @__kmpc_reduce_nowait(%struct.ident_t* [[DEF_LOC_2]], i32 [[TWO]], i32 1, i64 8, i8* [[SEVEN]], void (i8*, i8*)* [[RED_FUNC:@.+]], [8 x i32]* [[RED_VAR:@.+]]) + +// switch +// CK6: switch i32 [[EIGHT]], label [[RED_DEFAULT:%.+]] [ +// CK6: i32 1, label [[CASE1:%.+]] +// CK6: i32 2, label [[CASE2:%.+]] + +// case 1: +// CK6: [[NINE:%.+]] = load i32, i32* %0, align 4 +// CK6: [[TEN:%.+]] = load i32, i32* [[G_1]] +// CK6: [[ADD:%.+]] = add nsw i32 [[NINE]], [[TEN]] +// CK6: store i32 [[ADD]], i32* [[ZERO]] +// CK6: call void @__kmpc_end_reduce_nowait(%struct.ident_t* [[DEF_LOC_2]], i32 [[TWO]], [8 x i32]* [[GOMP]]) +// CK6: br label [[RED_DEFAULT]] + +// case 2: +// CK6: [[ELEVEN:%.+]] = load i32, i32* [[G_1]] +// CK6: [[TWELVE:%.+]] = atomicrmw add i32* [[ZERO]], i32 [[ELEVEN]] monotonic + +// CK6: define internal void [[RED_FUNC]](i8* [[ZERO]], i8* [[ONE]]) +// CK6: ret void +#endif +#ifdef CK7 +///==========================================================================/// +// RUN: %clang_cc1 -DCK7 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK7 +// RUN: %clang_cc1 -DCK7 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK7 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK7 + +// RUN: %clang_cc1 -DCK7 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// RUN: %clang_cc1 -DCK7 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK7 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// SIMD-ONLY0-NOT: {{__kmpc|__tgt}} + +// CK7-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// CK7-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" +// CK7-DAG: [[DEF_LOC_1:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } + +void parallel_master_if() { +#pragma omp parallel master if (parallel: false) + parallel_master_if(); +} + +// CK7-LABEL: parallel_master_if +// CK7: [[ZERO:%.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* [[DEF_LOC_1]]) +// CK7: call void @__kmpc_serialized_parallel(%struct.ident_t* [[DEF_LOC_1]], i32 [[ZERO]]) +// CK7: call void [[OUTLINED:@.+]](i32* [[THREAD_TEMP:%.+]], i32* [[BND_ADDR:%.+]]) +// CK7: call void @__kmpc_end_serialized_parallel(%struct.ident_t* [[DEF_LOC_1]], i32 [[ZERO]]) +// CK7: ret void + +// CK7: define internal void @.omp_outlined.(i32* noalias [[GTID:%.+]], i32* noalias [[BTID:%.+]]) +// CK7: [[EXECUTE:%.+]] = call i32 @__kmpc_master(%struct.ident_t* @0, i32 %1) +// CK7: call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_1]], i32 %1) + +#endif +#ifdef CK8 +///==========================================================================/// +// RUN: %clang_cc1 -DCK8 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK8 +// RUN: %clang_cc1 -DCK8 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK8 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK8 + +// RUN: %clang_cc1 -DCK8 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// RUN: %clang_cc1 -DCK8 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -DCK8 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s +// SIMD-ONLY0-NOT: {{__kmpc|__tgt}} + +typedef __INTPTR_TYPE__ intptr_t; + +// CK8-DAG: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* } +// CK8-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" +// CK8-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global [[IDENT_T_TY]] { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } + +void foo(); + +struct S { + intptr_t a, b, c; + S(intptr_t a) : a(a) {} + operator char() { return a; } + ~S() {} +}; + +template +T tmain() { +#pragma omp parallel master proc_bind(master) + foo(); + return T(); +} + +int main() { +#pragma omp parallel master proc_bind(spread) + foo(); +#pragma omp parallel master proc_bind(close) + foo(); + return tmain(); +} + +// CK8-LABEL: @main +// CK8: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEF_LOC_2]]) +// CK8: call {{.*}}void @__kmpc_push_proc_bind([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 4) +// CK8: call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call( +// CK8: call {{.*}}void @__kmpc_push_proc_bind([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 3) +// CK8: call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call( + +// CK8-LABEL: @{{.+}}tmain +// CK8: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEF_LOC_2]]) +// CK8: call {{.*}}void @__kmpc_push_proc_bind([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 2) +// CK8: call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call( +// CK8: ret i32 0 +// CK8-NEXT: } + +// CK8: call i32 @__kmpc_master(%struct.ident_t* [[DEF_LOC_2]], i32 [[ONE:%.+]]) +// CK8: call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_2]], i32 [[ONE]]) + +#endif +#ifdef CK9 +// CK9-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* } +// CK9-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00" +// CK9-DAG: [[DEF_LOC:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) } + +void parallel_master_firstprivate() { + int a; +#pragma omp parallel master firstprivate(a) allocate(a) + a++; +} + +// CK9-LABEL: define void @{{.+}}parallel_master_firstprivate{{.+}} +// CK9: [[A_VAL:%.+]] = alloca i32 +// CK9: [[A_CASTED:%.+]] = alloca i64 +// CK9: [[ZERO:%.+]] = load i32, i32* [[A_VAL]] +// CK9: [[CONV:%.+]] = bitcast i64* [[A_CASTED]] to i32* +// CK9: store i32 [[ZERO]], i32* [[CONV]] +// CK9: [[ONE:%.+]] = load i64, i64* [[A_CASTED]] +// CK9: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i64)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*), i64 [[ONE]]) + +// CK9: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]], i64 [[A_VAL]]) +// CK9: [[GLOBAL_TID_ADDR:%.+]] = alloca i32* +// CK9: [[BOUND_TID_ADDR:%.+]] = alloca i32* +// CK9: [[A_ADDR:%.+]] = alloca i64 +// CK9: store i32* [[GLOBAL_TID]], i32** [[GLOBAL_TID_ADDR]] +// CK9: store i32* [[BOUND_TID]], i32** [[BOUND_TID_ADDR]] +// CK9: store i64 [[A_VAL]], i64* [[A_ADDR]] +// CK9: [[CONV]] = bitcast i64* [[A_ADDR]] to i32* +// CK9-NOT: __kmpc_global_thread_num +// CK9: call i32 @__kmpc_master({{.+}}) +// CK9: [[FOUR:%.+]] = load i32, i32* [[CONV]] +// CK9: [[INC:%.+]] = add nsw i32 [[FOUR]] +// CK9: store i32 [[INC]], i32* [[CONV]] +// CK9-NOT: __kmpc_global_thread_num +// CK9: call void @__kmpc_end_master({{.+}}) +#endif +#endif diff --git a/clang/test/OpenMP/parallel_master_copyin_messages.cpp b/clang/test/OpenMP/parallel_master_copyin_messages.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_copyin_messages.cpp @@ -0,0 +1,115 @@ +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} +class S2 { + mutable int a; + +public: + S2() : a(0) {} + S2 &operator=(S2 &s2) { return *this; } +}; +class S3 { + int a; + +public: + S3() : a(0) {} + S3 &operator=(S3 &s3) { return *this; } +}; +class S4 { + int a; + S4(); + S4 &operator=(const S4 &s4); // expected-note {{implicitly declared private here}} + +public: + S4(int v) : a(v) {} +}; +class S5 { + int a; + S5() : a(0) {} + S5 &operator=(const S5 &s5) { return *this; } // expected-note {{implicitly declared private here}} + +public: + S5(int v) : a(v) {} +}; +template +class ST { +public: + static T s; +}; + +S2 k; +S3 h; +S4 l(3); +S5 m(4); +#pragma omp threadprivate(h, k, l, m) + +namespace A { +double x; +#pragma omp threadprivate(x) +} +namespace B { +using A::x; +} + +int main(int argc, char **argv) { + int i; +#pragma omp parallel master copyin // expected-error {{expected '(' after 'copyin'}} + { + foo(); + } +#pragma omp parallel master copyin( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master copyin() // expected-error {{expected expression}} + { + foo(); + } +#pragma omp parallel master copyin(k // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master copyin(h, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master copyin(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master copyin(l) // expected-error {{'operator=' is a private member of 'S4'}} + { + foo(); + } +#pragma omp parallel master copyin(S1) // expected-error {{'S1' does not refer to a value}} + { + foo(); + } +#pragma omp parallel master copyin(argv[1]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master copyin(i) // expected-error {{copyin variable must be threadprivate}} + { + foo(); + } +#pragma omp parallel master copyin(m) // expected-error {{'operator=' is a private member of 'S5'}} + { + foo(); + } +#pragma omp parallel master copyin(ST < int > ::s, B::x) // expected-error {{copyin variable must be threadprivate}} + { + foo(); + } + + return 0; +} diff --git a/clang/test/OpenMP/parallel_master_default_messages.cpp b/clang/test/OpenMP/parallel_master_default_messages.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_default_messages.cpp @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized + +void foo(); + +int main(int argc, char **argv) { +#pragma omp parallel master default // expected-error {{expected '(' after 'default'}} + { +#pragma omp parallel master default( // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { +#pragma omp parallel master default() // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} + { +#pragma omp parallel master default(none // expected-error {{expected ')'}} expected-note {{to match this '('}} + { +#pragma omp parallel master default(shared), default(shared) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'default' clause}} + { +#pragma omp parallel master default(x) // expected-error {{expected 'none' or 'shared' in OpenMP clause 'default'}} + { + foo(); + } + } + } + } + } + } + +#pragma omp parallel master default(none) // expected-note {{explicit data sharing attribute requested here}} + { + ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} + } + +#pragma omp parallel master default(none) // expected-note {{explicit data sharing attribute requested here}} + { +#pragma omp parallel master default(shared) + { + ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} + } + } + return 0; +} diff --git a/clang/test/OpenMP/parallel_master_firstprivate_messages.cpp b/clang/test/OpenMP/parallel_master_firstprivate_messages.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_firstprivate_messages.cpp @@ -0,0 +1,320 @@ +// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized + +extern int omp_default_mem_alloc; +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +void xxx(int argc) { + int fp; // expected-note {{initialize the variable 'fp' to silence this warning}} +#pragma omp parallel master firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}} + { + for (int i = 0; i < 10; ++i) + ; + } +} + +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) {} + S3(const S3 &s3) : a(s3.a) {} +}; +const S3 c; +const S3 ca[5]; +extern const int f; +class S4 { + int a; + S4(); + S4(const S4 &s4); // 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, z; + int &j = i; +#pragma omp parallel master firstprivate // expected-error {{expected '(' after 'firstprivate'}} + { + foo(); + } +#pragma omp parallel master firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master firstprivate() // expected-error {{expected expression}} + { + foo(); + } +#pragma omp parallel master firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master firstprivate(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}} + { + foo(); + } +#pragma omp parallel master firstprivate(S1) // expected-error {{'S1' does not refer to a value}} + { + foo(); + } +#pragma omp parallel master firstprivate(z, a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} + { + foo(); + } +#pragma omp parallel master firstprivate(argv[1]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} + { + foo(); + } +#pragma omp parallel master firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} + { + foo(); + } +#pragma omp parallel master linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel master'}} + { + foo(); + } +#pragma omp parallel + { + int v = 0; + int i; +#pragma omp parallel master firstprivate(i) + { + foo(); + } + v += i; + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp parallel master firstprivate(j) + { + foo(); + } +#pragma omp parallel master firstprivate(i) + { + foo(); + } +#pragma omp parallel master firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} + { + foo(); + } +#pragma omp parallel private(i) +#pragma omp parallel master firstprivate(i) + { + foo(); + } +#pragma omp parallel reduction(+ : i) +#pragma omp parallel master firstprivate(i) + { + foo(); + } + return 0; +} + +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, z; + int &j = i; +#pragma omp parallel master firstprivate // expected-error {{expected '(' after 'firstprivate'}} + { + foo(); + } +#pragma omp parallel master firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master firstprivate() // expected-error {{expected expression}} + { + foo(); + } +#pragma omp parallel master firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master firstprivate(argc, z) + { + foo(); + } +#pragma omp parallel master firstprivate(S1) // expected-error {{'S1' does not refer to a value}} + { + foo(); + } +#pragma omp parallel master firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} + { + foo(); + } +#pragma omp parallel master firstprivate(argv[1]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master firstprivate(2 * 2) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master firstprivate(ba) // OK + { + foo(); + } +#pragma omp parallel master firstprivate(ca) // OK + { + foo(); + } +#pragma omp parallel master firstprivate(da) // OK + { + foo(); + } + int xa; +#pragma omp parallel master firstprivate(xa) // OK + { + foo(); + } +#pragma omp parallel master firstprivate(S2::S2s) // OK + { + foo(); + } +#pragma omp parallel master firstprivate(S2::S2sc) // OK + { + foo(); + } +#pragma omp parallel master safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel master'}} + { + foo(); + } +#pragma omp parallel master firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} + { + foo(); + } +#pragma omp parallel master firstprivate(m) // OK + { + foo(); + } +#pragma omp parallel master firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}} + { + foo(); + } +#pragma omp parallel master private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} + { + foo(); + } +#pragma omp parallel shared(xa) +#pragma omp parallel master firstprivate(xa) // OK: may be firstprivate + { + foo(); + } +#pragma omp parallel master firstprivate(j) + { + foo(); + } +#pragma omp parallel master firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} + { + foo(); + } +#pragma omp parallel master firstprivate(n) // OK + { + foo(); + } +#pragma omp parallel + { + int v = 0; + int i; +#pragma omp parallel master firstprivate(i) + { + foo(); + } + v += i; + } +#pragma omp parallel private(i) +#pragma omp parallel master firstprivate(i) + { + foo(); + } +#pragma omp parallel reduction(+ : i) +#pragma omp parallel master firstprivate(i) + { + foo(); + } + static int r; +#pragma omp parallel master firstprivate(r) // OK + { + foo(); + } + + return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain' requested here}} +} diff --git a/clang/test/OpenMP/parallel_master_if_messages.cpp b/clang/test/OpenMP/parallel_master_if_messages.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_if_messages.cpp @@ -0,0 +1,173 @@ +// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -ferror-limit 100 %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ferror-limit 100 %s -Wuninitialized + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +void xxx(int argc) { + int cond; // expected-note {{initialize the variable 'cond' to silence this warning}} +#pragma omp parallel master if(cond) // expected-warning {{variable 'cond' is uninitialized when used here}} + { + ; + } +} + +struct S1; // expected-note {{declared here}} + +template // expected-note {{declared here}} +int tmain(T argc, S **argv) { + T z; + #pragma omp parallel master if // expected-error {{expected '(' after 'if'}} + { + foo(); + } + #pragma omp parallel master if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if () // expected-error {{expected expression}} + { + foo(); + } + #pragma omp parallel master if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + { + foo(); + } + #pragma omp parallel master if (argc > 0 ? argv[1] : argv[2]) + { + foo(); + } + #pragma omp parallel master if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'if' clause}} + { + foo(); + } + #pragma omp parallel master if (S) // expected-error {{'S' does not refer to a value}} + { + foo(); + } + #pragma omp parallel master if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if(argc + z) + { + foo(); + } + #pragma omp parallel master if(parallel : // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if(parallel : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if(parallel : argc) + { + foo(); + } + #pragma omp parallel master if(parallel : argc) if (for:argc) // expected-error {{directive name modifier 'for' is not allowed for '#pragma omp parallel master'}} + { + foo(); + } + #pragma omp parallel master if(parallel : argc) if (parallel:argc) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'if' clause with 'parallel' name modifier}} + { + foo(); + } + #pragma omp parallel master if(parallel : argc) if (argc) // expected-error {{no more 'if' clause is allowed}} expected-note {{previous clause with directive name modifier specified here}} + { + foo(); + } + + return 0; +} + +int main(int argc, char **argv) { + int z; + #pragma omp parallel master if // expected-error {{expected '(' after 'if'}} + { + foo(); + } + #pragma omp parallel master if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if () // expected-error {{expected expression}} + { + foo(); + } + #pragma omp parallel master if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + { + foo(); + } + #pragma omp parallel master if (argc > 0 ? argv[1] : argv[2] + z) + { + foo(); + } + #pragma omp parallel master if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'if' clause}} + { + foo(); + } + #pragma omp parallel master if (S1) // expected-error {{'S1' does not refer to a value}} + { + foo(); + } + #pragma omp parallel master if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if (1 0) // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if(if(tmain(argc, argv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if(parallel : // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if(parallel : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } + #pragma omp parallel master if(parallel : argc) + { + foo(); + } + #pragma omp parallel master if(parallel : argc) if (for:argc) // expected-error {{directive name modifier 'for' is not allowed for '#pragma omp parallel master'}} + { + foo(); + } + #pragma omp parallel master if(parallel : argc) if (parallel:argc) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'if' clause with 'parallel' name modifier}} + { + foo(); + } + #pragma omp parallel master if(parallel : argc) if (argc) // expected-error {{no more 'if' clause is allowed}} expected-note {{previous clause with directive name modifier specified here}} + { + foo(); + } + + return tmain(argc, argv); +} diff --git a/clang/test/OpenMP/parallel_master_message.cpp b/clang/test/OpenMP/parallel_master_message.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_message.cpp @@ -0,0 +1,88 @@ +// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized + +void xxx(int argc) { + int x; // expected-note {{initialize the variable 'x' to silence this warning}} +#pragma omp parallel master + argc = x; // expected-warning {{variable 'x' is uninitialized when used here}} +} + +#pragma omp parallel master // expected-error {{unexpected OpenMP directive '#pragma omp parallel master'}} + +int foo() { + return 0; +} + +int a; +struct S; +S& bar(); +int main(int argc, char **argv) { + #pragma omp parallel master nowait // expected-error {{unexpected OpenMP clause 'nowait' in directive '#pragma omp parallel master'}} + #pragma omp parallel master unknown // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + foo(); + { + #pragma omp master + } // expected-error {{expected statement}} + { + #pragma omp parallel master + } // expected-error {{expected statement}} + + S &s = bar(); + #pragma omp parallel master + (void)&s; + #pragma omp parallel master { // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + foo(); + #pragma omp parallel master ( // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + foo(); + #pragma omp parallel master [ // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + foo(); + #pragma omp parallel master ] // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + foo(); + #pragma omp parallel master ) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + foo(); + #pragma omp parallel master } // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + foo(); + #pragma omp parallel master + // expected-warning@+1 {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + #pragma omp parallel master unknown() + foo(); + L1: + foo(); + #pragma omp parallel master + ; + #pragma omp parallel master + { + + for (int i = 0; i < 10; ++i) { + switch(argc) { + case (0): + #pragma omp parallel master + { + foo(); + break; // expected-error {{'break' statement not in loop or switch statement}} + continue; // expected-error {{'continue' statement not in loop statement}} + } + default: + break; + } + } + goto L1; // expected-error {{use of undeclared label 'L1'}} + argc++; + } +#pragma omp parallel master default(none) // expected-note 2 {{explicit data sharing attribute requested here}} + { + ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}} + ++a; // expected-error {{variable 'a' must have explicitly specified data sharing attributes}} + } + + goto L2; // expected-error {{use of undeclared label 'L2'}} + #pragma omp parallel master + L2: + foo(); + #pragma omp parallel master + { + return 1; // expected-error {{cannot return from OpenMP region}} + } + return 0; +} diff --git a/clang/test/OpenMP/parallel_master_num_threads_messages.cpp b/clang/test/OpenMP/parallel_master_num_threads_messages.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_num_threads_messages.cpp @@ -0,0 +1,67 @@ +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized + +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) { + T z; + #pragma omp parallel master num_threads // expected-error {{expected '(' after 'num_threads'}} + {foo();} + #pragma omp parallel master num_threads ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + {foo();} + #pragma omp parallel master num_threads () // expected-error {{expected expression}} + {foo();} + #pragma omp parallel master num_threads (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + {foo();} + #pragma omp parallel master num_threads (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + {foo();} + #pragma omp parallel master num_threads ((argc > 0) ? argv[1] : argv[2]) // expected-error 2 {{expression must have integral or unscoped enumeration type, not 'char *'}} + {foo();} + #pragma omp parallel master num_threads (foobool(argc)), num_threads (true), num_threads (-5) // expected-error 2 {{directive '#pragma omp parallel master' cannot contain more than one 'num_threads' clause}} expected-error {{argument to 'num_threads' clause must be a strictly positive integer value}} + {foo();} + #pragma omp parallel master num_threads (S) // expected-error {{'S' does not refer to a value}} + {foo();} + #pragma omp parallel master num_threads (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error 2 {{expression must have integral or unscoped enumeration type, not 'char *'}} + {foo();} + #pragma omp parallel master num_threads (argc + z) + {foo();} + #pragma omp parallel master num_threads (N) // expected-error {{argument to 'num_threads' clause must be a strictly positive integer value}} + {foo();} + + return argc; +} + +int main(int argc, char **argv) { + int z; + #pragma omp parallel master num_threads // expected-error {{expected '(' after 'num_threads'}} + {foo();} + #pragma omp parallel master num_threads ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + {foo();} + #pragma omp parallel master num_threads () // expected-error {{expected expression}} + {foo();} + #pragma omp parallel master num_threads (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + {foo();} + #pragma omp parallel master num_threads (argc / z)) // expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + {foo();} + #pragma omp parallel master num_threads (argc > 0 ? argv[1] : argv[2]) // expected-error {{integral }} + {foo();} + #pragma omp parallel master num_threads (foobool(argc)), num_threads (true), num_threads (-5) // expected-error 2 {{directive '#pragma omp parallel master' cannot contain more than one 'num_threads' clause}} expected-error {{argument to 'num_threads' clause must be a strictly positive integer value}} + {foo();} + #pragma omp parallel master num_threads (S1) // expected-error {{'S1' does not refer to a value}} + {foo();} + #pragma omp parallel master num_threads (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expression must have integral or unscoped enumeration type, not 'char *'}} + {foo();} + #pragma omp parallel master num_threads (num_threads(tmain(argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}} expected-note {{in instantiation of function template specialization 'tmain' requested here}} + {foo();} + + return tmain(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain' requested here}} +} diff --git a/clang/test/OpenMP/parallel_master_private_messages.cpp b/clang/test/OpenMP/parallel_master_private_messages.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_private_messages.cpp @@ -0,0 +1,284 @@ +// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized + +extern int omp_default_mem_alloc; +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) { +#pragma omp parallel master private(a) private(this->a) + { + for (int k = 0; k < v; ++k) + ++this->a; + } + } +}; +class S5 { + int a; + S5() : a(0) {} // expected-note {{implicitly declared private here}} + +public: + S5(int v) : a(v) {} + S5 &operator=(S5 &s) { +#pragma omp parallel master private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}} + { + for (int k = 0; k < s.a; ++k) + ++s.a; + } + return *this; + } +}; + +template +class S6 { +public: + T a; + + S6() : a(0) {} + S6(T v) : a(v) { +#pragma omp parallel master private(a) private(this->a) + { + for (int k = 0; k < v; ++k) + ++this->a; + } + } + S6 &operator=(S6 &s) { +#pragma omp parallel master private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}} + { + for (int k = 0; k < s.a; ++k) + ++s.a; + } + return *this; + } +}; + +template +class S7 : public T { + T a; + S7() : a(0) {} + +public: + S7(T v) : a(v) { +#pragma omp parallel master private(a) private(this->a) private(T::a) + { + for (int k = 0; k < a.a; ++k) + ++this->a.a; + } + } + S7 &operator=(S7 &s) { +#pragma omp parallel master private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}} + { + for (int k = 0; k < s.a.a; ++k) + ++s.a.a; + } + return *this; + } +}; + +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, z; + int &j = i; +#pragma omp parallel master private // expected-error {{expected '(' after 'private'}} + { + foo(); + } +#pragma omp parallel master private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master private() // expected-error {{expected expression}} + { + foo(); + } +#pragma omp parallel master private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master private(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}} + { + foo(); + } +#pragma omp parallel master private(S1) // expected-error {{'S1' does not refer to a value}} + { + foo(); + } +#pragma omp parallel master private(a, b) // expected-error {{private variable with incomplete type 'S1'}} + { + foo(); + } +#pragma omp parallel master private(argv[1]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master private(e, g, z) + { + foo(); + } +#pragma omp parallel master private(h) // expected-error {{threadprivate or thread local variable cannot be private}} + { + foo(); + } +#pragma omp parallel master copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel master'}} + { + foo(); + } +#pragma omp parallel + { + int v = 0; + int i; +#pragma omp parallel master private(i) + { + foo(); + } + v += i; + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp parallel master private(j) + { + foo(); + } +#pragma omp parallel master private(i) + { + foo(); + } + return 0; +} + +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); + S6 s6(0.0) , s6_0(1.0); + S7 > s7(0.0) , s7_0(1.0); + int i, z; + int &j = i; +#pragma omp parallel master private // expected-error {{expected '(' after 'private'}} + { + foo(); + } +#pragma omp parallel master private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master private() // expected-error {{expected expression}} + { + foo(); + } +#pragma omp parallel master private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master private(argc, z) + { + foo(); + } +#pragma omp parallel master private(S1) // expected-error {{'S1' does not refer to a value}} + { + foo(); + } +#pragma omp parallel master private(a, b) // expected-error {{private variable with incomplete type 'S1'}} + { + foo(); + } +#pragma omp parallel master private(argv[1]) // expected-error {{expected variable name}} + { + foo(); + } +#pragma omp parallel master private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} + { + foo(); + } +#pragma omp parallel master private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}} + { + foo(); + } +#pragma omp parallel master copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel master'}} + { + foo(); + } +#pragma omp parallel + { + int i; +#pragma omp parallel master private(i) + { + foo(); + } + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp parallel master private(j) + { + foo(); + } +#pragma omp parallel master private(i) + { + foo(); + } + static int m; +#pragma omp parallel master private(m) + { + foo(); + } + + s6 = s6_0; // expected-note {{in instantiation of member function 'S6::operator=' requested here}} + s7 = s7_0; // expected-note {{in instantiation of member function 'S7 >::operator=' requested here}} + return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain' requested here}} +} + diff --git a/clang/test/OpenMP/parallel_master_proc_bind_messages.cpp b/clang/test/OpenMP/parallel_master_proc_bind_messages.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_proc_bind_messages.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized + +void foo(); + +int main(int argc, char **argv) { +#pragma omp parallel master proc_bind // expected-error {{expected '(' after 'proc_bind'}} + { foo(); } +#pragma omp parallel master proc_bind( // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { foo(); } +#pragma omp parallel master proc_bind() // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}} + { foo(); } +#pragma omp parallel master proc_bind(master // expected-error {{expected ')'}} expected-note {{to match this '('}} + { foo(); } +#pragma omp parallel master proc_bind(close), proc_bind(spread) // expected-error {{directive '#pragma omp parallel master' cannot contain more than one 'proc_bind' clause}} + { foo(); } +#pragma omp parallel master proc_bind(x) // expected-error {{expected 'master', 'close' or 'spread' in OpenMP clause 'proc_bind'}} + { foo(); } + +#pragma omp parallel master proc_bind(master) + { ++argc; } + +#pragma omp parallel master proc_bind(close) + { +#pragma omp parallel master proc_bind(spread) + { ++argc; } + } + return 0; +} diff --git a/clang/test/OpenMP/parallel_master_reduction_messages.cpp b/clang/test/OpenMP/parallel_master_reduction_messages.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_reduction_messages.cpp @@ -0,0 +1,398 @@ +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 150 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp -std=c++11 -ferror-limit 150 -o - %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 150 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-simd -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized +// RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -ferror-limit 150 -o - %s -Wuninitialized + +extern int omp_default_mem_alloc; +void xxx(int argc) { + int fp; // expected-note {{initialize the variable 'fp' to silence this warning}} +#pragma omp parallel master reduction(+:fp) // expected-warning {{variable 'fp' is uninitialized when used here}} +{ + for (int i = 0; i < 10; ++i) + ; +} +} + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +void foobar(int &ref) { +#pragma omp parallel master reduction(+:ref) + { + foo(); + } +} + +struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; + S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}} + +public: + S2() : a(0) {} + S2(S2 &s2) : a(s2.a) {} + static float S2s; // expected-note 2 {{static data member is predetermined as shared}} + static const float S2sc; // expected-note 2 {{'S2sc' declared here}} +}; +const float S2::S2sc = 0; +S2 b; // expected-note 3 {{'b' defined here}} +const S2 ba[5]; // expected-note 2 {{'ba' defined here}} +class S3 { + int a; + +public: + int b; + S3() : a(0) {} + S3(const S3 &s3) : a(s3.a) {} + S3 operator+(const S3 &arg1) { return arg1; } +}; +int operator+(const S3 &arg1, const S3 &arg2) { return 5; } +S3 c; // expected-note 3 {{'c' defined here}} +const S3 ca[5]; // expected-note 2 {{'ca' defined here}} +extern const int f; // expected-note 4 {{'f' declared here}} +class S4 { + int a; + S4(); // expected-note {{implicitly declared private here}} + S4(const S4 &s4); + S4 &operator+(const S4 &arg) { return (*this); } + +public: + S4(int v) : a(v) {} +}; +S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; } +class S5 { + int a; + S5() : a(0) {} // expected-note {{implicitly declared private here}} + S5(const S5 &s5) : a(s5.a) {} + S5 &operator+(const S5 &arg); + +public: + S5(int v) : a(v) {} +}; +class S6 { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}} +#if __cplusplus >= 201103L // C++11 or later +// expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}} +#endif + int a; + +public: + S6() : a(6) {} + operator int() { return 6; } +} o; + +S3 h, k; +#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} + +template // expected-note {{declared here}} +T tmain(T argc) { + const T d = T(); // expected-note 4 {{'d' defined here}} + const T da[5] = {T()}; // expected-note 2 {{'da' defined here}} + T qa[5] = {T()}; + T i, z; + T &j = i; // expected-note 4 {{'j' defined here}} + S3 &p = k; // expected-note 2 {{'p' defined here}} + const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}} + T &q = qa[(int)i]; // expected-note 2 {{'q' defined here}} + T fl; +#pragma omp parallel master reduction // expected-error {{expected '(' after 'reduction'}} + { + foo(); + } +#pragma omp parallel master reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + { + foo(); + } +#pragma omp parallel master reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} + { + foo(); + } +#pragma omp parallel master reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} + { + foo(); + } +#pragma omp parallel master reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} + { + foo(); + } +#pragma omp parallel master reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}} + { + foo(); + } +#pragma omp parallel master reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}} + { + foo(); + } +#pragma omp parallel master reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}} + { + foo(); + } +#pragma omp parallel master reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'float'}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'}} + { + foo(); + } +#pragma omp parallel master reduction(&& : argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}} + { + foo(); + } +#pragma omp parallel master reduction(^ : T) // expected-error {{'T' does not refer to a value}} + { + foo(); + } +#pragma omp parallel master reduction(+ : z, a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 3 {{const-qualified variable cannot be reduction}} expected-error 2 {{'operator+' is a private member of 'S2'}} + { + foo(); + } +#pragma omp parallel master reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 4 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 3 {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(max : h.b) // expected-error {{expected variable name, array element or array section}} + { + foo(); + } +#pragma omp parallel master reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}} expected-error {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}} + { + foo(); + } +#pragma omp parallel master reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(+ : o) // expected-error 2 {{no viable overloaded '='}} + { + foo(); + } +#pragma omp parallel master private(i), reduction(+ : j), reduction(+ : q) // expected-error 4 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + { + foo(); + } +#pragma omp parallel private(k) +#pragma omp parallel master reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + { + foo(); + } +#pragma omp parallel master reduction(+ : p), reduction(+ : p) // expected-error 2 {{variable can appear only once in OpenMP 'reduction' clause}} expected-note 2 {{previously referenced here}} + { + foo(); + } +#pragma omp parallel master reduction(+ : r) // expected-error 2 {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel shared(i) +#pragma omp parallel reduction(min : i) +#pragma omp parallel master reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + { + foo(); + } +#pragma omp parallel private(fl) +#pragma omp parallel master reduction(+ : fl) + { + foo(); + } +#pragma omp parallel reduction(* : fl) +#pragma omp parallel master reduction(+ : fl) + { + foo(); + } + + return T(); +} + +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 2 {{'d' defined here}} + const int da[5] = {0}; // expected-note {{'da' defined here}} + int qa[5] = {0}; + S4 e(4); + S5 g(5); + int i, z; + int &j = i; // expected-note 2 {{'j' defined here}} + S3 &p = k; // expected-note 2 {{'p' defined here}} + const int &r = da[i]; // expected-note {{'r' defined here}} + int &q = qa[i]; // expected-note {{'q' defined here}} + float fl; +#pragma omp parallel master reduction // expected-error {{expected '(' after 'reduction'}} + { + foo(); + } +#pragma omp parallel master reduction + // expected-error {{expected '(' after 'reduction'}} expected-warning {{extra tokens at the end of '#pragma omp parallel master' are ignored}} + { + foo(); + } +#pragma omp parallel master reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} + { + foo(); + } +#pragma omp parallel master reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected expression}} + { + foo(); + } +#pragma omp parallel master reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} + { + foo(); + } +#pragma omp parallel master reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}} + { + foo(); + } +#pragma omp parallel master reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { + foo(); + } +#pragma omp parallel master reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}} + { + foo(); + } +#pragma omp parallel master reduction(~ : argc) // expected-error {{expected unqualified-id}} + { + foo(); + } +#pragma omp parallel master reduction(&& : argc) + { + foo(); + } +#pragma omp parallel master reduction(^ : S1) // expected-error {{'S1' does not refer to a value}} + { + foo(); + } +#pragma omp parallel master reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{const-qualified variable cannot be reduction}} expected-error {{'operator+' is a private member of 'S2'}} + { + foo(); + } +#pragma omp parallel master reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 2 {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(max : h.b) // expected-error {{expected variable name, array element or array section}} + { + foo(); + } +#pragma omp parallel master reduction(+ : ba) // expected-error {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(* : ca) // expected-error {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(- : da) // expected-error {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}} + { + foo(); + } +#pragma omp parallel master reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(& : e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{invalid operands to binary expression ('S4' and 'S4')}} expected-error {{calling a private constructor of class 'S5'}} expected-error {{invalid operands to binary expression ('S5' and 'S5')}} + { + foo(); + } +#pragma omp parallel master reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel master reduction(+ : o, z) // expected-error {{no viable overloaded '='}} + { + foo(); + } +#pragma omp parallel master private(i), reduction(+ : j), reduction(+ : q) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + { + foo(); + } +#pragma omp parallel private(k) +#pragma omp parallel master reduction(+ : p), reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + { + foo(); + } +#pragma omp parallel master reduction(+ : p), reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'reduction' clause}} expected-note {{previously referenced here}} + { + foo(); + } +#pragma omp parallel master reduction(+ : r) // expected-error {{const-qualified variable cannot be reduction}} + { + foo(); + } +#pragma omp parallel shared(i) +#pragma omp parallel reduction(min : i) +#pragma omp parallel master reduction(max : j) // expected-error {{argument of OpenMP clause 'reduction' must reference the same object in all threads}} + { + foo(); + } +#pragma omp parallel private(fl) +#pragma omp parallel master reduction(+ : fl) + { + foo(); + } +#pragma omp parallel reduction(* : fl) +#pragma omp parallel master reduction(+ : fl) + { + foo(); + } + static int m; +#pragma omp parallel master reduction(+ : m) // OK + { + foo(); + } + + return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain' requested here}} expected-note {{in instantiation of function template specialization 'tmain' requested here}} +} diff --git a/clang/test/OpenMP/parallel_master_shared_messages.cpp b/clang/test/OpenMP/parallel_master_shared_messages.cpp new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/parallel_master_shared_messages.cpp @@ -0,0 +1,120 @@ +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s -Wuninitialized + +// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} +extern S1 a; +class S2 { + mutable int a; + +public: + S2() : a(0) {} + S2(S2 &s2) : a(s2.a) {} +}; +const S2 b; +const S2 ba[5]; +class S3 { + int a; + +public: + S3() : a(0) {} + S3(S3 &s3) : a(s3.a) {} +}; +const S3 c; +const S3 ca[5]; +extern const int f; +class S4 { + int a; + S4(); + S4(const S4 &s4); + +public: + S4(int v) : a(v) {} +}; +class S5 { + int a; + S5() : a(0) {} + S5(const S5 &s5) : a(s5.a) {} + +public: + S5(int v) : a(v) {} +}; + +S3 h; +#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}} + +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); + int i, k; + int &j = i; +#pragma omp parallel master shared // expected-error {{expected '(' after 'shared'}} + { foo(); } +#pragma omp parallel master shared( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { foo(); } +#pragma omp parallel master shared() // expected-error {{expected expression}} + { foo(); } +#pragma omp parallel master shared(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + { foo(); } +#pragma omp parallel master shared(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + { foo(); } +#pragma omp parallel master shared(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + { foo(); } +#pragma omp parallel master shared(argc) + { foo(); } +#pragma omp parallel master shared(S1) // expected-error {{'S1' does not refer to a value}} + { foo(); } +#pragma omp parallel master shared(a, b, c, d, f, k) + { foo(); } +#pragma omp parallel master shared(argv[1]) // expected-error {{expected variable name}} + { foo(); } +#pragma omp parallel master shared(ba) + { foo(); } +#pragma omp parallel master shared(ca) + { foo(); } +#pragma omp parallel master shared(da) + { foo(); } +#pragma omp parallel master shared(e, g) + { foo(); } +#pragma omp parallel master shared(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be shared}} + { foo(); } +#pragma omp parallel master private(i), shared(i) // expected-error {{private variable cannot be shared}} expected-note {{defined as private}} + { foo(); } +#pragma omp parallel master firstprivate(i), shared(i) // expected-error {{firstprivate variable cannot be shared}} expected-note {{defined as firstprivate}} + { foo(); } +#pragma omp parallel master private(i) + { +#pragma omp parallel master shared(i) + { +#pragma omp parallel master shared(j) + { foo(); } + } + } +#pragma omp parallel master firstprivate(i) + { +#pragma omp parallel master shared(i) + { +#pragma omp parallel master shared(j) + { foo(); } + } + } + + return 0; +} diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2030,6 +2030,7 @@ void VisitOMPCriticalDirective(const OMPCriticalDirective *D); void VisitOMPParallelForDirective(const OMPParallelForDirective *D); void VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective *D); + void VisitOMPParallelMasterDirective(const OMPParallelMasterDirective *D); void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D); void VisitOMPTaskDirective(const OMPTaskDirective *D); void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D); @@ -2811,6 +2812,11 @@ VisitOMPLoopDirective(D); } +void EnqueueVisitor::VisitOMPParallelMasterDirective( + const OMPParallelMasterDirective *D) { + VisitOMPExecutableDirective(D); +} + void EnqueueVisitor::VisitOMPParallelSectionsDirective( const OMPParallelSectionsDirective *D) { VisitOMPExecutableDirective(D); @@ -5455,6 +5461,8 @@ return cxstring::createRef("OMPParallelForDirective"); case CXCursor_OMPParallelForSimdDirective: return cxstring::createRef("OMPParallelForSimdDirective"); + case CXCursor_OMPParallelMasterDirective: + return cxstring::createRef("OMPParallelMasterDirective"); case CXCursor_OMPParallelSectionsDirective: return cxstring::createRef("OMPParallelSectionsDirective"); case CXCursor_OMPTaskDirective: diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -610,6 +610,9 @@ case Stmt::OMPParallelForSimdDirectiveClass: K = CXCursor_OMPParallelForSimdDirective; break; + case Stmt::OMPParallelMasterDirectiveClass: + K = CXCursor_OMPParallelMasterDirective; + break; case Stmt::OMPParallelSectionsDirectiveClass: K = CXCursor_OMPParallelSectionsDirective; break;