Index: cfe/trunk/docs/LibASTMatchersReference.html =================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html +++ cfe/trunk/docs/LibASTMatchersReference.html @@ -1375,6 +1375,20 @@ +
Matches any ``#pragma omp`` executable directive. + +Given + + #pragma omp parallel + #pragma omp parallel default(none) + #pragma omp taskyield + +``ompExecutableDirective()`` matches ``omp parallel``, +``omp parallel default(none)`` and ``omp taskyield``. +
Matches opaque value expressions. They are used as helpers to reference another expressions and can be met Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -60,6 +60,7 @@ #include "clang/AST/Stmt.h" #include "clang/AST/StmtCXX.h" #include "clang/AST/StmtObjC.h" +#include "clang/AST/StmtOpenMP.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" @@ -6369,6 +6370,29 @@ return false; } +//----------------------------------------------------------------------------// +// OpenMP handling. +//----------------------------------------------------------------------------// + +/// Matches any ``#pragma omp`` executable directive. +/// +/// Given +/// +/// \code +/// #pragma omp parallel +/// #pragma omp parallel default(none) +/// #pragma omp taskyield +/// \endcode +/// +/// ``ompExecutableDirective()`` matches ``omp parallel``, +/// ``omp parallel default(none)`` and ``omp taskyield``. +extern const internal::VariadicDynCastAllOfMatcher+ ompExecutableDirective; + +//----------------------------------------------------------------------------// +// End OpenMP handling. +//----------------------------------------------------------------------------// + } // namespace ast_matchers } // namespace clang Index: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp =================================================================== --- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp +++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -845,5 +845,8 @@ AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType, PointerType, ReferenceType)); +const internal::VariadicDynCastAllOfMatcher + ompExecutableDirective; + } // end namespace ast_matchers } // end namespace clang Index: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp +++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp @@ -434,6 +434,7 @@ REGISTER_MATCHER(objcThrowStmt); REGISTER_MATCHER(objcTryStmt); REGISTER_MATCHER(ofClass); + REGISTER_MATCHER(ompExecutableDirective); REGISTER_MATCHER(on); REGISTER_MATCHER(onImplicitObjectArgument); REGISTER_MATCHER(opaqueValueExpr); Index: cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp =================================================================== --- cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp +++ cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp @@ -28,10 +28,6 @@ AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); } const ast_matchers::internal::VariadicDynCastAllOfMatcher< - Stmt, OMPExecutableDirective> - ompExecutableDirective; - -const ast_matchers::internal::VariadicDynCastAllOfMatcher< OMPExecutableDirective, OMPTargetDirective> ompTargetDirective; Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp =================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1765,5 +1765,29 @@ EXPECT_FALSE(matchesObjC(ObjCStringNoPool, autoreleasePoolStmt())); } +TEST(OMPExecutableDirective, Matches) { + auto Matcher = stmt(ompExecutableDirective()); + + const std::string Source0 = R"( +void x() { +#pragma omp parallel +; +})"; + EXPECT_TRUE(matchesWithOpenMP(Source0, Matcher)); + + const std::string Source1 = R"( +void x() { +#pragma omp taskyield +; +})"; + EXPECT_TRUE(matchesWithOpenMP(Source1, Matcher)); + + const std::string Source2 = R"( +void x() { +; +})"; + EXPECT_TRUE(notMatchesWithOpenMP(Source2, Matcher)); +} + } // namespace ast_matchers } // namespace clang Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h =================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h @@ -235,6 +235,18 @@ } template +testing::AssertionResult matchesWithOpenMP(const std::string &Code, + const T &AMatcher) { + return matchesConditionally(Code, AMatcher, true, "-fopenmp"); +} + +template +testing::AssertionResult notMatchesWithOpenMP(const std::string &Code, + const T &AMatcher) { + return matchesConditionally(Code, AMatcher, false, "-fopenmp"); +} + +template testing::AssertionResult matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher, std::unique_ptr FindResultVerifier,