Add hasAttr matcher for declarations.
Delete special-case CUDA attribute matchers.
Patch by Jacques Pienaar.
llvm-svn: 216379
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index 7a639aa..9263736 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -649,22 +649,23 @@
EXPECT_TRUE(matches("void f() { int i; }", CannotMemoize));
}
+TEST(DeclarationMatcher, HasAttr) {
+ EXPECT_TRUE(matches("struct __attribute__((warn_unused)) X {};",
+ decl(hasAttr(clang::attr::WarnUnused))));
+ EXPECT_FALSE(matches("struct X {};",
+ decl(hasAttr(clang::attr::WarnUnused))));
+}
+
TEST(DeclarationMatcher, MatchCudaDecl) {
EXPECT_TRUE(matchesWithCuda("__global__ void f() { }"
"void g() { f<<<1, 2>>>(); }",
CUDAKernelCallExpr()));
EXPECT_TRUE(matchesWithCuda("__attribute__((device)) void f() {}",
- hasCudaDeviceAttr()));
- EXPECT_TRUE(matchesWithCuda("__attribute__((host)) void f() {}",
- hasCudaHostAttr()));
- EXPECT_TRUE(matchesWithCuda("__attribute__((global)) void f() {}",
- hasCudaGlobalAttr()));
- EXPECT_FALSE(matchesWithCuda("void f() {}",
- hasCudaGlobalAttr()));
+ hasAttr(clang::attr::CUDADevice)));
EXPECT_TRUE(notMatchesWithCuda("void f() {}",
- hasCudaGlobalAttr()));
+ CUDAKernelCallExpr()));
EXPECT_FALSE(notMatchesWithCuda("__attribute__((global)) void f() {}",
- hasCudaGlobalAttr()));
+ hasAttr(clang::attr::CUDAGlobal)));
}
// Implements a run method that returns whether BoundNodes contains a
diff --git a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
index 5552790..f8a9430 100644
--- a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -472,6 +472,14 @@
"Matcher<NamedDecl> hasName(string)"));
}
+TEST_F(RegistryTest, HasArgs) {
+ Matcher<Decl> Value = constructMatcher(
+ "decl", constructMatcher("hasAttr", std::string("attr::WarnUnused")))
+ .getTypedMatcher<Decl>();
+ EXPECT_TRUE(matches("struct __attribute__((warn_unused)) X {};", Value));
+ EXPECT_FALSE(matches("struct X {};", Value));
+}
+
} // end anonymous namespace
} // end namespace dynamic
} // end namespace ast_matchers