From d1e40fbfe1c38f5778c739d1fc1b3bcf156ccb58 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Thu, 26 Jun 2014 12:05:45 +0000 Subject: [PATCH] [OPENMP] Initial parsing and sema analysis for 'single' directive. llvm-svn: 211774 --- clang/include/clang-c/Index.h | 6 +- clang/include/clang/AST/DataRecursiveASTVisitor.h | 5 + clang/include/clang/AST/RecursiveASTVisitor.h | 5 + clang/include/clang/AST/StmtOpenMP.h | 57 +++++ clang/include/clang/Basic/OpenMPKinds.def | 10 + clang/include/clang/Basic/StmtNodes.td | 1 + clang/include/clang/Sema/Sema.h | 5 + clang/include/clang/Serialization/ASTBitCodes.h | 1 + clang/lib/AST/Stmt.cpp | 26 +++ clang/lib/AST/StmtPrinter.cpp | 5 + clang/lib/AST/StmtProfile.cpp | 4 + clang/lib/Basic/OpenMPKinds.cpp | 14 +- clang/lib/CodeGen/CGStmt.cpp | 3 + clang/lib/CodeGen/CGStmtOpenMP.cpp | 4 + clang/lib/CodeGen/CodeGenFunction.h | 1 + clang/lib/Parse/ParseOpenMP.cpp | 6 +- clang/lib/Sema/SemaOpenMP.cpp | 19 ++ clang/lib/Sema/TreeTransform.h | 10 + clang/lib/Serialization/ASTReaderStmt.cpp | 12 ++ clang/lib/Serialization/ASTWriterStmt.cpp | 7 + clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 1 + clang/test/OpenMP/nesting_of_regions.cpp | 112 ++++++++++ clang/test/OpenMP/single_ast_print.cpp | 38 ++++ clang/test/OpenMP/single_firstprivate_messages.cpp | 239 +++++++++++++++++++++ clang/test/OpenMP/single_misc_messages.c | 151 +++++++++++++ clang/test/OpenMP/single_private_messages.cpp | 140 ++++++++++++ clang/tools/libclang/CIndex.cpp | 7 + clang/tools/libclang/CXCursor.cpp | 3 + 28 files changed, 887 insertions(+), 5 deletions(-) create mode 100644 clang/test/OpenMP/single_ast_print.cpp create mode 100644 clang/test/OpenMP/single_firstprivate_messages.cpp create mode 100644 clang/test/OpenMP/single_misc_messages.c create mode 100644 clang/test/OpenMP/single_private_messages.cpp diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 909e2db..561bed9 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -2151,7 +2151,11 @@ enum CXCursorKind { */ CXCursor_OMPSectionDirective = 236, - CXCursor_LastStmt = CXCursor_OMPSectionDirective, + /** \brief OpenMP single directive. + */ + CXCursor_OMPSingleDirective = 237, + + CXCursor_LastStmt = CXCursor_OMPSingleDirective, /** * \brief Cursor that represents the translation unit itself. diff --git a/clang/include/clang/AST/DataRecursiveASTVisitor.h b/clang/include/clang/AST/DataRecursiveASTVisitor.h index 536d372..86d6ca8 100644 --- a/clang/include/clang/AST/DataRecursiveASTVisitor.h +++ b/clang/include/clang/AST/DataRecursiveASTVisitor.h @@ -2305,6 +2305,11 @@ DEF_TRAVERSE_STMT(OMPSectionDirective, { return false; }) +DEF_TRAVERSE_STMT(OMPSingleDirective, { + if (!TraverseOMPExecutableDirective(S)) + return false; +}) + // OpenMP clauses. template bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index eae370e..14a957e 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2327,6 +2327,11 @@ DEF_TRAVERSE_STMT(OMPSectionDirective, { return false; }) +DEF_TRAVERSE_STMT(OMPSingleDirective, { + if (!TraverseOMPExecutableDirective(S)) + return false; +}) + // OpenMP clauses. template bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h index 8b954f45..59f24fa 100644 --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -470,6 +470,63 @@ public: } }; +/// \brief This represents '#pragma omp single' directive. +/// +/// \code +/// #pragma omp single private(a,b) copyprivate(c,d) +/// \endcode +/// In this example directive '#pragma omp single' has clauses 'private' with +/// the variables 'a' and 'b' and 'copyprivate' with variables 'c' and 'd'. +/// +class OMPSingleDirective : public OMPExecutableDirective { + friend class ASTStmtReader; + /// \brief Build directive with the given start and end location. + /// + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending location of the directive. + /// \param NumClauses Number of clauses. + /// + OMPSingleDirective(SourceLocation StartLoc, SourceLocation EndLoc, + unsigned NumClauses) + : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single, + StartLoc, EndLoc, NumClauses, 1) {} + + /// \brief Build an empty directive. + /// + /// \param NumClauses Number of clauses. + /// + explicit OMPSingleDirective(unsigned NumClauses) + : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single, + SourceLocation(), SourceLocation(), NumClauses, + 1) {} + +public: + /// \brief Creates directive with a list of \a Clauses. + /// + /// \param C AST context. + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending Location of the directive. + /// \param Clauses List of clauses. + /// \param AssociatedStmt Statement, associated with the directive. + /// + static OMPSingleDirective * + Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, + ArrayRef Clauses, Stmt *AssociatedStmt); + + /// \brief Creates an empty directive with the place for \a NumClauses + /// clauses. + /// + /// \param C AST context. + /// \param NumClauses Number of clauses. + /// + static OMPSingleDirective *CreateEmpty(const ASTContext &C, + unsigned NumClauses, EmptyShell); + + static bool classof(const Stmt *T) { + return T->getStmtClass() == OMPSingleDirectiveClass; + } +}; + } // end namespace clang #endif diff --git a/clang/include/clang/Basic/OpenMPKinds.def b/clang/include/clang/Basic/OpenMPKinds.def index c47782b..67ce712 100644 --- a/clang/include/clang/Basic/OpenMPKinds.def +++ b/clang/include/clang/Basic/OpenMPKinds.def @@ -30,6 +30,9 @@ #ifndef OPENMP_SECTIONS_CLAUSE # define OPENMP_SECTIONS_CLAUSE(Name) #endif +#ifndef OPENMP_SINGLE_CLAUSE +# define OPENMP_SINGLE_CLAUSE(Name) +#endif #ifndef OPENMP_DEFAULT_KIND # define OPENMP_DEFAULT_KIND(Name) #endif @@ -48,6 +51,7 @@ OPENMP_DIRECTIVE(simd) OPENMP_DIRECTIVE(for) OPENMP_DIRECTIVE(sections) OPENMP_DIRECTIVE(section) +OPENMP_DIRECTIVE(single) // OpenMP clauses. OPENMP_CLAUSE(if, OMPIfClause) @@ -104,6 +108,11 @@ OPENMP_SECTIONS_CLAUSE(firstprivate) OPENMP_SECTIONS_CLAUSE(reduction) OPENMP_SECTIONS_CLAUSE(nowait) +// TODO more clauses allowed for directive 'omp single'. +OPENMP_SINGLE_CLAUSE(private) +OPENMP_SINGLE_CLAUSE(firstprivate) +OPENMP_SINGLE_CLAUSE(nowait) + // Static attributes for 'default' clause. OPENMP_DEFAULT_KIND(none) OPENMP_DEFAULT_KIND(shared) @@ -125,6 +134,7 @@ OPENMP_SCHEDULE_KIND(runtime) #undef OPENMP_DEFAULT_KIND #undef OPENMP_DIRECTIVE #undef OPENMP_CLAUSE +#undef OPENMP_SINGLE_CLAUSE #undef OPENMP_SECTIONS_CLAUSE #undef OPENMP_PARALLEL_CLAUSE #undef OPENMP_SIMD_CLAUSE diff --git a/clang/include/clang/Basic/StmtNodes.td b/clang/include/clang/Basic/StmtNodes.td index 5236f46..17a56ad 100644 --- a/clang/include/clang/Basic/StmtNodes.td +++ b/clang/include/clang/Basic/StmtNodes.td @@ -182,3 +182,4 @@ def OMPSimdDirective : DStmt; def OMPForDirective : DStmt; def OMPSectionsDirective : DStmt; def OMPSectionDirective : DStmt; +def OMPSingleDirective : DStmt; diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 0a6cd33..700bda0 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7331,6 +7331,11 @@ public: /// associated statement. StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); + /// \brief Called on well-formed '\#pragma omp single' after parsing of the + /// associated statement. + StmtResult ActOnOpenMPSingleDirective(ArrayRef Clauses, + Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc); OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index 55cf34f..fe91b15 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -1344,6 +1344,7 @@ namespace clang { STMT_OMP_FOR_DIRECTIVE, STMT_OMP_SECTIONS_DIRECTIVE, STMT_OMP_SECTION_DIRECTIVE, + STMT_OMP_SINGLE_DIRECTIVE, // ARC EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp index b402f6e..5245944 100644 --- a/clang/lib/AST/Stmt.cpp +++ b/clang/lib/AST/Stmt.cpp @@ -1430,3 +1430,29 @@ OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C, return new (Mem) OMPSectionDirective(); } +OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C, + SourceLocation StartLoc, + SourceLocation EndLoc, + ArrayRef Clauses, + Stmt *AssociatedStmt) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), + llvm::alignOf()); + void *Mem = + C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); + OMPSingleDirective *Dir = + new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size()); + Dir->setClauses(Clauses); + Dir->setAssociatedStmt(AssociatedStmt); + return Dir; +} + +OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C, + unsigned NumClauses, + EmptyShell) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), + llvm::alignOf()); + void *Mem = + C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); + return new (Mem) OMPSingleDirective(NumClauses); +} + diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 0ac6833..4a46063 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -797,6 +797,11 @@ void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) { PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) { + Indent() << "#pragma omp single "; + PrintOMPExecutableDirective(Node); +} + //===----------------------------------------------------------------------===// // Expr printing methods. //===----------------------------------------------------------------------===// diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 804003f..f3f3c7b 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -368,6 +368,10 @@ void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) { VisitOMPExecutableDirective(S); } +void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) { + VisitOMPExecutableDirective(S); +} + void StmtProfiler::VisitExpr(const Expr *S) { VisitStmt(S); } diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp index 547eb32..623af2d 100644 --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -201,6 +201,16 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, break; } break; + case OMPD_single: + switch (CKind) { +#define OPENMP_SINGLE_CLAUSE(Name) \ + case OMPC_##Name: \ + return true; +#include "clang/Basic/OpenMPKinds.def" + default: + break; + } + break; case OMPD_unknown: case OMPD_threadprivate: case OMPD_task: @@ -215,8 +225,8 @@ bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) { } bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) { - return DKind == OMPD_for || DKind == OMPD_sections || - DKind == OMPD_section; // TODO add next directives. + return DKind == OMPD_for || DKind == OMPD_sections || DKind == OMPD_section || + DKind == OMPD_single; // TODO add next directives. } bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) { diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index c3ad8b36..8edee89 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -188,6 +188,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::OMPSectionDirectiveClass: EmitOMPSectionDirective(cast(*S)); break; + case Stmt::OMPSingleDirectiveClass: + EmitOMPSingleDirective(cast(*S)); + break; } } diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index ae45aa4..805eeaf 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -87,3 +87,7 @@ void CodeGenFunction::EmitOMPSectionDirective(const OMPSectionDirective &) { llvm_unreachable("CodeGen for 'omp section' is not supported yet."); } +void CodeGenFunction::EmitOMPSingleDirective(const OMPSingleDirective &) { + llvm_unreachable("CodeGen for 'omp single' is not supported yet."); +} + diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 8745399..2fe2b9b 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1905,6 +1905,7 @@ public: void EmitOMPForDirective(const OMPForDirective &S); void EmitOMPSectionsDirective(const OMPSectionsDirective &S); void EmitOMPSectionDirective(const OMPSectionDirective &S); + void EmitOMPSingleDirective(const OMPSingleDirective &S); //===--------------------------------------------------------------------===// // LValue Expression Emission diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 11e888e..102cab3 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -65,6 +65,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { case OMPD_for: case OMPD_sections: case OMPD_section: + case OMPD_single: Diag(Tok, diag::err_omp_unexpected_directive) << getOpenMPDirectiveName(DKind); break; @@ -80,8 +81,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { /// annot_pragma_openmp_end /// /// executable-directive: -/// annot_pragma_openmp 'parallel'|'simd'|'for'|'sections'|'section' -/// {clause} annot_pragma_openmp_end +/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | +/// 'section' | 'single' {clause} annot_pragma_openmp_end /// StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() { assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); @@ -121,6 +122,7 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() { case OMPD_simd: case OMPD_for: case OMPD_sections: + case OMPD_single: case OMPD_section: { ConsumeToken(); diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index ba441a2..7f3560f 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -924,6 +924,13 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, SourceLocation Loc, ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params); break; } + case OMPD_single: { + Sema::CapturedParamNameType Params[] = { + std::make_pair(StringRef(), QualType()) // __context with shared vars + }; + ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params); + break; + } case OMPD_threadprivate: case OMPD_task: llvm_unreachable("OpenMP Directive is not allowed"); @@ -1033,6 +1040,10 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, "No clauses is allowed for 'omp section' directive"); Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); break; + case OMPD_single: + Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, + EndLoc); + break; case OMPD_threadprivate: case OMPD_task: llvm_unreachable("OpenMP Directive is not allowed"); @@ -1647,6 +1658,14 @@ StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt); } +StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef Clauses, + Stmt *AStmt, + SourceLocation StartLoc, + SourceLocation EndLoc) { + getCurFunction()->setHasBranchProtectedScope(); + return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); +} + OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, SourceLocation StartLoc, SourceLocation LParenLoc, diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 5920873..974f5e0 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6449,6 +6449,16 @@ TreeTransform::TransformOMPSectionDirective(OMPSectionDirective *D) { return Res; } +template +StmtResult +TreeTransform::TransformOMPSingleDirective(OMPSingleDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr); + StmtResult Res = getDerived().TransformOMPExecutableDirective(D); + getDerived().getSema().EndOpenMPDSABlock(Res.get()); + return Res; +} + //===----------------------------------------------------------------------===// // OpenMP clause transformation //===----------------------------------------------------------------------===// diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index 6649b6f..ea8d0f3 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1918,6 +1918,13 @@ void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) { VisitOMPExecutableDirective(D); } +void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) { + VisitStmt(D); + // The NumClauses field was read in ReadStmtFromStream. + ++Idx; + VisitOMPExecutableDirective(D); +} + //===----------------------------------------------------------------------===// // ASTReader Implementation //===----------------------------------------------------------------------===// @@ -2422,6 +2429,11 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { S = OMPSectionDirective::CreateEmpty(Context, Empty); break; + case STMT_OMP_SINGLE_DIRECTIVE: + S = OMPSingleDirective::CreateEmpty( + Context, Record[ASTStmtReader::NumStmtFields], Empty); + break; + case EXPR_CXX_OPERATOR_CALL: S = new (Context) CXXOperatorCallExpr(Context, Empty); break; diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index 10a55b2..1292ec8 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1831,6 +1831,13 @@ void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) { Code = serialization::STMT_OMP_SECTION_DIRECTIVE; } +void ASTStmtWriter::VisitOMPSingleDirective(OMPSingleDirective *D) { + VisitStmt(D); + Record.push_back(D->getNumClauses()); + VisitOMPExecutableDirective(D); + Code = serialization::STMT_OMP_SINGLE_DIRECTIVE; +} + //===----------------------------------------------------------------------===// // ASTWriter Implementation //===----------------------------------------------------------------------===// diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 244862d..ba30c5c 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -735,6 +735,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::OMPForDirectiveClass: case Stmt::OMPSectionsDirectiveClass: case Stmt::OMPSectionDirectiveClass: + case Stmt::OMPSingleDirectiveClass: llvm_unreachable("Stmt should not be in analyzer evaluation loop"); case Stmt::ObjCSubscriptRefExprClass: diff --git a/clang/test/OpenMP/nesting_of_regions.cpp b/clang/test/OpenMP/nesting_of_regions.cpp index 9d0ee29..79f3cd6 100644 --- a/clang/test/OpenMP/nesting_of_regions.cpp +++ b/clang/test/OpenMP/nesting_of_regions.cpp @@ -22,6 +22,9 @@ void foo() { { bar(); } +#pragma omp parallel +#pragma omp single + bar(); #pragma omp simd for (int i = 0; i < 10; ++i) { #pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}} @@ -54,6 +57,13 @@ void foo() { bar(); } } +#pragma omp simd + for (int i = 0; i < 10; ++i) { +#pragma omp single // expected-error {{OpenMP constructs may not be nested inside a simd region}} + { + bar(); + } + } #pragma omp for for (int i = 0; i < 10; ++i) { #pragma omp for // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} @@ -86,6 +96,13 @@ void foo() { bar(); } } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp single // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + { + bar(); + } + } #pragma omp sections { #pragma omp for // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} @@ -118,10 +135,50 @@ void foo() { 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 section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} { bar(); } +#pragma omp single + { +#pragma omp for // expected-error {{region cannot be closely nested inside 'single' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp single + { +#pragma omp simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp single + { +#pragma omp parallel + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp single + { +#pragma omp single // expected-error {{region cannot be closely nested inside 'single' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp single + { +#pragma omp sections // expected-error {{region cannot be closely nested inside 'single' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}} + { + bar(); + } + } } void foo() { @@ -143,6 +200,14 @@ void foo() { { bar(); } +#pragma omp parallel +#pragma omp sections + { + bar(); + } +#pragma omp parallel +#pragma omp single + bar(); #pragma omp simd for (int i = 0; i < 10; ++i) { #pragma omp for // expected-error {{OpenMP constructs may not be nested inside a simd region}} @@ -175,6 +240,11 @@ void foo() { bar(); } } +#pragma omp simd + for (int i = 0; i < 10; ++i) { +#pragma omp single // expected-error {{OpenMP constructs may not be nested inside a simd region}} + bar(); + } #pragma omp for for (int i = 0; i < 10; ++i) { #pragma omp for // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} @@ -207,6 +277,11 @@ void foo() { bar(); } } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp single // expected-error {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + bar(); + } #pragma omp sections { #pragma omp for // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} @@ -239,10 +314,47 @@ void foo() { bar(); } } +#pragma omp sections + { +#pragma omp single // expected-error {{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + bar(); + } #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} { bar(); } +#pragma omp single + { +#pragma omp for // expected-error {{region cannot be closely nested inside 'single' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp single + { +#pragma omp simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp single + { +#pragma omp parallel + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp single + { +#pragma omp single // expected-error {{region cannot be closely nested inside 'single' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp single + { +#pragma omp sections // expected-error {{region cannot be closely nested inside 'single' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}} + { + bar(); + } + } return foo(); } diff --git a/clang/test/OpenMP/single_ast_print.cpp b/clang/test/OpenMP/single_ast_print.cpp new file mode 100644 index 0000000..eaae114 --- /dev/null +++ b/clang/test/OpenMP/single_ast_print.cpp @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ast-print %s | FileCheck %s +// RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp=libiomp5 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +void foo() {} + +template +T tmain(T argc) { + T b = argc, c, d, e, f, g; + static T a; +// CHECK: static T a; +#pragma omp parallel +#pragma omp single private(argc, b), firstprivate(c, d), nowait + foo(); + // CHECK-NEXT: #pragma omp parallel + // CHECK-NEXT: #pragma omp single private(argc,b) firstprivate(c,d) nowait + // CHECK-NEXT: foo(); + return T(); +} + +int main(int argc, char **argv) { + int b = argc, c, d, e, f, g; + static int a; +// CHECK: static int a; +#pragma omp parallel +#pragma omp single private(argc, b), firstprivate(argv, c), nowait + foo(); + // CHECK-NEXT: #pragma omp parallel + // CHECK-NEXT: #pragma omp single private(argc,b) firstprivate(argv,c) nowait + // CHECK-NEXT: foo(); + return (tmain(argc) + tmain(argv[0][0])); +} + +#endif diff --git a/clang/test/OpenMP/single_firstprivate_messages.cpp b/clang/test/OpenMP/single_firstprivate_messages.cpp new file mode 100644 index 0000000..6d49882 --- /dev/null +++ b/clang/test/OpenMP/single_firstprivate_messages.cpp @@ -0,0 +1,239 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; + +public: + S2() : a(0) {} + S2(S2 &s2) : a(s2.a) {} + 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(S3 &s3) : a(s3.a) {} +}; +const S3 c; +const S3 ca[5]; +extern const int f; +class S4 { // expected-note 2 {{'S4' declared here}} + int a; + S4(); + S4(const S4 &s4); + +public: + S4(int v) : a(v) {} +}; +class S5 { // expected-note 4 {{'S5' declared here}} + int a; + S5(const S5 &s5) : a(s5.a) {} + +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); // expected-note {{'e' defined here}} + C g(5); // expected-note 2 {{'g' defined here}} + int i; + int &j = i; // expected-note {{'j' defined here}} +#pragma omp parallel +#pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate() // expected-error {{expected expression}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argc) + foo(); +#pragma omp parallel +#pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(e, g) // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} + foo(); +#pragma omp parallel +#pragma omp single linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp single'}} + foo(); +#pragma omp parallel + { + int v = 0; + int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp single' directive into a parallel or another task region?}} +#pragma omp single firstprivate(i) // expected-error {{private variable cannot be firstprivate}} + foo(); + v += i; + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp single firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(i) + foo(); +#pragma omp parallel +#pragma omp single firstprivate(g) // expected-error {{firstprivate variable must have an accessible, unambiguous copy constructor}} + foo(); +#pragma omp parallel private(i) // expected-note {{defined as private}} +#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} + foo(); +#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} +#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} + foo(); + return 0; +} + +int main(int argc, char **argv) { + const int d = 5; + const int da[5] = {0}; + S4 e(4); // expected-note {{'e' defined here}} + S5 g(5); // expected-note 2 {{'g' defined here}} + S3 m; + S6 n(2); + int i; + int &j = i; // expected-note {{'j' defined here}} +#pragma omp parallel +#pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate() // expected-error {{expected expression}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argc) + foo(); +#pragma omp parallel +#pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(2 * 2) // expected-error {{expected variable name}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(ba) // OK + foo(); +#pragma omp parallel +#pragma omp single firstprivate(ca) // OK + foo(); +#pragma omp parallel +#pragma omp single firstprivate(da) // OK + foo(); + int xa; +#pragma omp parallel +#pragma omp single firstprivate(xa) // OK + foo(); +#pragma omp parallel +#pragma omp single firstprivate(S2::S2s) // OK + foo(); +#pragma omp parallel +#pragma omp single firstprivate(S2::S2sc) // OK + foo(); +#pragma omp parallel +#pragma omp single safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp single'}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(e, g) // expected-error 2 {{firstprivate variable must have an accessible, unambiguous copy constructor}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(m) // OK + foo(); +#pragma omp parallel +#pragma omp single firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} + foo(); +#pragma omp parallel +#pragma omp single private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} + foo(); +#pragma omp parallel shared(xa) +#pragma omp single firstprivate(xa) // OK: may be firstprivate + foo(); +#pragma omp parallel +#pragma omp single firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(g) // expected-error {{firstprivate variable must have an accessible, unambiguous copy constructor}} + foo(); +#pragma omp parallel +#pragma omp single firstprivate(n) // OK + foo(); +#pragma omp parallel + { + int v = 0; + int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp single' directive into a parallel or another task region?}} +#pragma omp single firstprivate(i) // expected-error {{private variable cannot be firstprivate}} + foo(); + v += i; + } +#pragma omp parallel private(i) // expected-note {{defined as private}} +#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} + foo(); +#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} +#pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}} + foo(); + + return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain' requested here}} +} diff --git a/clang/test/OpenMP/single_misc_messages.c b/clang/test/OpenMP/single_misc_messages.c new file mode 100644 index 0000000..8667b50 --- /dev/null +++ b/clang/test/OpenMP/single_misc_messages.c @@ -0,0 +1,151 @@ +// RUN: %clang_cc1 -fsyntax-only -fopenmp=libiomp5 -verify %s + +void foo(); + +// expected-error@+1 {{unexpected OpenMP directive '#pragma omp single'}} +#pragma omp single + +// expected-error@+1 {{unexpected OpenMP directive '#pragma omp single'}} +#pragma omp single foo + +void test_no_clause() { + int i; +#pragma omp single + foo(); + +#pragma omp single + ++i; +} + +void test_branch_protected_scope() { + int i = 0; +L1: + ++i; + + int x[24]; + +#pragma omp parallel +#pragma omp single + { + if (i == 5) + goto L1; // expected-error {{use of undeclared label 'L1'}} + else if (i == 6) + return; // expected-error {{cannot return from OpenMP region}} + else if (i == 7) + goto L2; + else if (i == 8) { + L2: + x[i]++; + } + } + + if (x[0] == 0) + goto L2; // expected-error {{use of undeclared label 'L2'}} + else if (x[1] == 1) + goto L1; +} + +void test_invalid_clause() { + int i; +#pragma omp parallel +// expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}} +#pragma omp single foo bar + foo(); +} + +void test_non_identifiers() { + int i, x; + +#pragma omp parallel +// expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}} +#pragma omp single; + foo(); +#pragma omp parallel +// expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp single'}} +// expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}} +#pragma omp single linear(x); + foo(); + +#pragma omp parallel +// expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}} +#pragma omp single private(x); + foo(); + +#pragma omp parallel +// expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}} +#pragma omp single, private(x); + foo(); +} + +void test_private() { + int i; +#pragma omp parallel +// expected-error@+2 {{expected expression}} +// expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}} +#pragma omp single private( + foo(); +#pragma omp parallel +// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} +// expected-error@+1 2 {{expected expression}} +#pragma omp single private(, + foo(); +#pragma omp parallel +// expected-error@+1 2 {{expected expression}} +#pragma omp single private(, ) + foo(); +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp single private() + foo(); +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp single private(int) + foo(); +#pragma omp parallel +// expected-error@+1 {{expected variable name}} +#pragma omp single private(0) + foo(); + + int x, y, z; +#pragma omp parallel +#pragma omp single private(x) + foo(); +#pragma omp parallel +#pragma omp single private(x, y) + foo(); +#pragma omp parallel +#pragma omp single private(x, y, z) + foo(); +} + +void test_firstprivate() { + int i; +#pragma omp parallel +// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} +// expected-error@+1 {{expected expression}} +#pragma omp single firstprivate( + foo(); + +#pragma omp parallel +// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}} +// expected-error@+1 2 {{expected expression}} +#pragma omp single firstprivate(, + foo(); +#pragma omp parallel +// expected-error@+1 2 {{expected expression}} +#pragma omp single firstprivate(, ) + foo(); +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp single firstprivate() + foo(); +#pragma omp parallel +// expected-error@+1 {{expected expression}} +#pragma omp single firstprivate(int) + foo(); +#pragma omp parallel +// expected-error@+1 {{expected variable name}} +#pragma omp single firstprivate(0) + foo(); +} + diff --git a/clang/test/OpenMP/single_private_messages.cpp b/clang/test/OpenMP/single_private_messages.cpp new file mode 100644 index 0000000..1414a92 --- /dev/null +++ b/clang/test/OpenMP/single_private_messages.cpp @@ -0,0 +1,140 @@ +// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; + +public: + S2() : a(0) {} +}; +const S2 b; +const S2 ba[5]; +class S3 { + int a; + +public: + S3() : a(0) {} +}; +const S3 ca[5]; +class S4 { // expected-note {{'S4' declared here}} + int a; + S4(); + +public: + S4(int v) : a(v) {} +}; +class S5 { // expected-note {{'S5' declared here}} + int a; + S5() : a(0) {} + +public: + S5(int v) : a(v) {} +}; + +S3 h; +#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} + +template +int foomain(I argc, C **argv) { + I e(4); + I g(5); + int i; + int &j = i; // expected-note {{'j' defined here}} +#pragma omp single private // expected-error {{expected '(' after 'private'}} + foo(); +#pragma omp single private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp single private() // expected-error {{expected expression}} + foo(); +#pragma omp single private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp single private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp single private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + foo(); +#pragma omp single private(argc) + foo(); +#pragma omp single private(S1) // expected-error {{'S1' does not refer to a value}} + foo(); +#pragma omp single private(a, b) // expected-error {{private variable with incomplete type 'S1'}} + foo(); +#pragma omp single private(argv[1]) // expected-error {{expected variable name}} + foo(); +#pragma omp single private(e, g) + foo(); +#pragma omp single private(h) // expected-error {{threadprivate or thread local variable cannot be private}} + foo(); +#pragma omp single shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp single'}} + foo(); +#pragma omp parallel + { + int v = 0; + int i; +#pragma omp single private(i) + foo(); + v += i; + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp single private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type}} + foo(); +#pragma omp single private(i) + foo(); + return 0; +} + +int main(int argc, char **argv) { + S4 e(4); // expected-note {{'e' defined here}} + S5 g(5); // expected-note {{'g' defined here}} + int i; + int &j = i; // expected-note {{'j' defined here}} +#pragma omp single private // expected-error {{expected '(' after 'private'}} + foo(); +#pragma omp single private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp single private() // expected-error {{expected expression}} + foo(); +#pragma omp single private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp single private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + foo(); +#pragma omp single private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + foo(); +#pragma omp single private(argc) + foo(); +#pragma omp single private(S1) // expected-error {{'S1' does not refer to a value}} + foo(); +#pragma omp single private(a, b) // expected-error {{private variable with incomplete type 'S1'}} + foo(); +#pragma omp single private(argv[1]) // expected-error {{expected variable name}} + foo(); +#pragma omp single private(e, g) // expected-error 2 {{private variable must have an accessible, unambiguous default constructor}} + foo(); +#pragma omp single private(h) // expected-error {{threadprivate or thread local variable cannot be private}} + foo(); +#pragma omp single shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp single'}} + foo(); +#pragma omp parallel + { + int i; +#pragma omp single private(i) + foo(); + } +#pragma omp parallel shared(i) +#pragma omp parallel private(i) +#pragma omp single private(j) // expected-error {{arguments of OpenMP clause 'private' cannot be of reference type}} + foo(); +#pragma omp single private(i) + foo(); + + return 0; +} + diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 2b7c8f5..93cb050 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -1854,6 +1854,7 @@ public: void VisitOMPForDirective(const OMPForDirective *D); void VisitOMPSectionsDirective(const OMPSectionsDirective *D); void VisitOMPSectionDirective(const OMPSectionDirective *D); + void VisitOMPSingleDirective(const OMPSingleDirective *D); private: void AddDeclarationNameInfo(const Stmt *S); @@ -2297,6 +2298,10 @@ void EnqueueVisitor::VisitOMPSectionDirective(const OMPSectionDirective *D) { VisitOMPExecutableDirective(D); } +void EnqueueVisitor::VisitOMPSingleDirective(const OMPSingleDirective *D) { + VisitOMPExecutableDirective(D); +} + void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) { EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S); } @@ -3979,6 +3984,8 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) { return cxstring::createRef("OMPSectionsDirective"); case CXCursor_OMPSectionDirective: return cxstring::createRef("OMPSectionDirective"); + case CXCursor_OMPSingleDirective: + return cxstring::createRef("OMPSingleDirective"); } llvm_unreachable("Unhandled CXCursorKind"); diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index 8a5077c..f3a3a6e 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -528,6 +528,9 @@ CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent, case Stmt::OMPSectionDirectiveClass: K = CXCursor_OMPSectionDirective; break; + case Stmt::OMPSingleDirectiveClass: + K = CXCursor_OMPSingleDirective; + break; } CXCursor C = { K, 0, { Parent, S, TU } }; -- 2.7.4