summaryrefslogtreecommitdiffstats
path: root/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp')
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp168
1 files changed, 168 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index a7e3d5082ea..1802eba2e18 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2274,5 +2274,173 @@ TEST(Matcher, isMain) {
notMatches("int main2() {}", functionDecl(isMain())));
}
+TEST(OMPExecutableDirective, hasClause) {
+ auto Matcher = ompExecutableDirective(hasAnyClause(anything()));
+
+ const std::string Source0 = R"(
+void x() {
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+ const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+ const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+ const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
+
+ const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPDefaultClause, isNoneKind) {
+ auto Matcher =
+ ompExecutableDirective(hasAnyClause(ompDefaultClause(isNoneKind())));
+
+ const std::string Source0 = R"(
+void x() {
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+ const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+ const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+ const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source3, Matcher));
+
+ const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPDefaultClause, isSharedKind) {
+ auto Matcher =
+ ompExecutableDirective(hasAnyClause(ompDefaultClause(isSharedKind())));
+
+ const std::string Source0 = R"(
+void x() {
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+ const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+ const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+ const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source3, Matcher));
+
+ const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPExecutableDirective, isAllowedToContainClauseKind) {
+ auto Matcher =
+ ompExecutableDirective(isAllowedToContainClauseKind(OMPC_default));
+
+ const std::string Source0 = R"(
+void x() {
+;
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+ const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source1, Matcher));
+
+ const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+ const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
+
+ const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+
+ const std::string Source5 = R"(
+void x() {
+#pragma omp taskyield
+})";
+ EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher));
+
+ const std::string Source6 = R"(
+void x() {
+#pragma omp task
+;
+})";
+ EXPECT_TRUE(matchesWithOpenMP(Source6, Matcher));
+}
+
} // namespace ast_matchers
} // namespace clang
OpenPOWER on IntegriCloud