summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2014-06-26 12:05:45 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2014-06-26 12:05:45 +0000
commitf0a57f4453809e08ae1b4feaeec2c91c5257af48 (patch)
tree63157d4916525a53de363118a4a7aad768dadd1e
parent0eca5e96c1b22228c8efe6a99df123186bfb340b (diff)
downloadclang-f0a57f4453809e08ae1b4feaeec2c91c5257af48.tar.gz
clang-f0a57f4453809e08ae1b4feaeec2c91c5257af48.tar.bz2
clang-f0a57f4453809e08ae1b4feaeec2c91c5257af48.tar.xz
[OPENMP] Initial parsing and sema analysis for 'single' directive.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211774 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang-c/Index.h6
-rw-r--r--include/clang/AST/DataRecursiveASTVisitor.h5
-rw-r--r--include/clang/AST/RecursiveASTVisitor.h5
-rw-r--r--include/clang/AST/StmtOpenMP.h57
-rw-r--r--include/clang/Basic/OpenMPKinds.def10
-rw-r--r--include/clang/Basic/StmtNodes.td1
-rw-r--r--include/clang/Sema/Sema.h5
-rw-r--r--include/clang/Serialization/ASTBitCodes.h1
-rw-r--r--lib/AST/Stmt.cpp26
-rw-r--r--lib/AST/StmtPrinter.cpp5
-rw-r--r--lib/AST/StmtProfile.cpp4
-rw-r--r--lib/Basic/OpenMPKinds.cpp14
-rw-r--r--lib/CodeGen/CGStmt.cpp3
-rw-r--r--lib/CodeGen/CGStmtOpenMP.cpp4
-rw-r--r--lib/CodeGen/CodeGenFunction.h1
-rw-r--r--lib/Parse/ParseOpenMP.cpp6
-rw-r--r--lib/Sema/SemaOpenMP.cpp19
-rw-r--r--lib/Sema/TreeTransform.h10
-rw-r--r--lib/Serialization/ASTReaderStmt.cpp12
-rw-r--r--lib/Serialization/ASTWriterStmt.cpp7
-rw-r--r--lib/StaticAnalyzer/Core/ExprEngine.cpp1
-rw-r--r--test/OpenMP/nesting_of_regions.cpp112
-rw-r--r--test/OpenMP/single_ast_print.cpp38
-rw-r--r--test/OpenMP/single_firstprivate_messages.cpp239
-rw-r--r--test/OpenMP/single_misc_messages.c151
-rw-r--r--test/OpenMP/single_private_messages.cpp140
-rw-r--r--tools/libclang/CIndex.cpp7
-rw-r--r--tools/libclang/CXCursor.cpp3
28 files changed, 887 insertions, 5 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 909e2dbfe2..561bed9231 100644
--- a/include/clang-c/Index.h
+++ b/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/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h
index 536d372ec4..86d6ca8667 100644
--- a/include/clang/AST/DataRecursiveASTVisitor.h
+++ b/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 <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h
index eae370e0b8..14a957e1cf 100644
--- a/include/clang/AST/RecursiveASTVisitor.h
+++ b/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 <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
diff --git a/include/clang/AST/StmtOpenMP.h b/include/clang/AST/StmtOpenMP.h
index 8b954f45e7..59f24facb3 100644
--- a/include/clang/AST/StmtOpenMP.h
+++ b/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<OMPClause *> 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/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def
index c47782b816..67ce712ed5 100644
--- a/include/clang/Basic/OpenMPKinds.def
+++ b/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/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td
index 5236f46883..17a56adcf6 100644
--- a/include/clang/Basic/StmtNodes.td
+++ b/include/clang/Basic/StmtNodes.td
@@ -182,3 +182,4 @@ def OMPSimdDirective : DStmt<OMPExecutableDirective>;
def OMPForDirective : DStmt<OMPExecutableDirective>;
def OMPSectionsDirective : DStmt<OMPExecutableDirective>;
def OMPSectionDirective : DStmt<OMPExecutableDirective>;
+def OMPSingleDirective : DStmt<OMPExecutableDirective>;
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index 0a6cd33b8d..700bda08c6 100644
--- a/include/clang/Sema/Sema.h
+++ b/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<OMPClause *> Clauses,
+ Stmt *AStmt, SourceLocation StartLoc,
+ SourceLocation EndLoc);
OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
Expr *Expr,
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h
index 55cf34fc73..fe91b15d99 100644
--- a/include/clang/Serialization/ASTBitCodes.h
+++ b/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/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index b402f6edd2..5245944e85 100644
--- a/lib/AST/Stmt.cpp
+++ b/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<OMPClause *> Clauses,
+ Stmt *AssociatedStmt) {
+ unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective),
+ llvm::alignOf<OMPClause *>());
+ 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<OMPClause *>());
+ void *Mem =
+ C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
+ return new (Mem) OMPSingleDirective(NumClauses);
+}
+
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index 0ac683347f..4a46063df3 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/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/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp
index 804003fb67..f3f3c7ba8e 100644
--- a/lib/AST/StmtProfile.cpp
+++ b/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/lib/Basic/OpenMPKinds.cpp b/lib/Basic/OpenMPKinds.cpp
index 547eb32199..623af2df60 100644
--- a/lib/Basic/OpenMPKinds.cpp
+++ b/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/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index c3ad8b369c..8edee89e74 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -188,6 +188,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) {
case Stmt::OMPSectionDirectiveClass:
EmitOMPSectionDirective(cast<OMPSectionDirective>(*S));
break;
+ case Stmt::OMPSingleDirectiveClass:
+ EmitOMPSingleDirective(cast<OMPSingleDirective>(*S));
+ break;
}
}
diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp
index ae45aa4abb..805eeaf40d 100644
--- a/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/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/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 87453992b1..2fe2b9bc36 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/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/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp
index 11e888efb4..102cab36e9 100644
--- a/lib/Parse/ParseOpenMP.cpp
+++ b/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/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp
index ba441a2b14..7f3560fc01 100644
--- a/lib/Sema/SemaOpenMP.cpp
+++ b/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<OMPClause *> 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/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 59208737b7..974f5e061b 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -6449,6 +6449,16 @@ TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
return Res;
}
+template <typename Derived>
+StmtResult
+TreeTransform<Derived>::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/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp
index 6649b6f05e..ea8d0f3ac9 100644
--- a/lib/Serialization/ASTReaderStmt.cpp
+++ b/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/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp
index 10a55b2889..1292ec8aa8 100644
--- a/lib/Serialization/ASTWriterStmt.cpp
+++ b/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/lib/StaticAnalyzer/Core/ExprEngine.cpp b/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 244862d0de..ba30c5c360 100644
--- a/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/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/test/OpenMP/nesting_of_regions.cpp b/test/OpenMP/nesting_of_regions.cpp
index 9d0ee29ec3..79f3cd6782 100644
--- a/test/OpenMP/nesting_of_regions.cpp
+++ b/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<int>();
}
diff --git a/test/OpenMP/single_ast_print.cpp b/test/OpenMP/single_ast_print.cpp
new file mode 100644
index 0000000000..eaae114960
--- /dev/null
+++ b/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 <class T, int N>
+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<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
+}
+
+#endif
diff --git a/test/OpenMP/single_firstprivate_messages.cpp b/test/OpenMP/single_firstprivate_messages.cpp
new file mode 100644
index 0000000000..6d4988254f
--- /dev/null
+++ b/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 <class I, class C>
+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<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
+}
diff --git a/test/OpenMP/single_misc_messages.c b/test/OpenMP/single_misc_messages.c
new file mode 100644
index 0000000000..8667b50469
--- /dev/null
+++ b/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/test/OpenMP/single_private_messages.cpp b/test/OpenMP/single_private_messages.cpp
new file mode 100644
index 0000000000..1414a92ee0
--- /dev/null
+++ b/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 <class I, class C>
+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/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 2b7c8f50bb..93cb0500df 100644
--- a/tools/libclang/CIndex.cpp
+++ b/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/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index 8a5077c12a..f3a3a6ea6b 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/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 } };