Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -1612,33 +1612,16 @@ -Matcher<Decl>hasCudaDeviceAttr -
Matches declaration that has CUDA device attribute.
+Matcher<Decl>hasAttr
+
Matches declaration that has a given attribute.
 
 Given
   __attribute__((device)) void f() { ... }
-matches the function declaration of f.
+decl(hasAttr<clang::CUDADeviceAttr>()) matches the function declaration of
+f.
 
-Matcher<Decl>hasCudaGlobalAttr -
Matches declaration that has CUDA global attribute.
-
-Given
-  __attribute__((global)) void f() { ... }
-matches the function declaration of f.
-
- - -Matcher<Decl>hasCudaHostAttr -
Matches declaration that has CUDA host attribute.
-
-Given
-  __attribute__((host)) void f() { ... }
-matches the function declaration of f.
-
- - Matcher<Decl>isImplicit
Matches a declaration that has been implicitly added
 by the compiler (eg. implicit defaultcopy constructors).
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3658,48 +3658,28 @@
   return InnerMatcher.matches(*Node.getLHS(), Finder, Builder);
 }
 
-/// \brief Matches CUDA kernel call expression.
+/// \brief Matches declaration that has a given attribute.
 ///
-/// Example matches,
-/// \code
-///   kernel<<>>();
-/// \endcode
-const internal::VariadicDynCastAllOfMatcher
-    CUDAKernelCallExpr;
-
-/// \brief Matches declaration that has CUDA device attribute.
-///
 /// Given
 /// \code
 ///   __attribute__((device)) void f() { ... }
 /// \endcode
-/// matches the function declaration of f.
-AST_MATCHER(Decl, hasCudaDeviceAttr) {
-  return Node.hasAttr();
+/// decl(hasAttr()) matches the function declaration of
+/// f.
+template 
+inline internal::Matcher hasAttr() {
+  return internal::HasAttrMatcher();
 }
 
-/// \brief Matches declaration that has CUDA host attribute.
+/// \brief Matches CUDA kernel call expression.
 ///
-/// Given
+/// Example matches,
 /// \code
-///   __attribute__((host)) void f() { ... }
+///   kernel<<>>();
 /// \endcode
-/// matches the function declaration of f.
-AST_MATCHER(Decl, hasCudaHostAttr) {
-  return Node.hasAttr();
-}
+const internal::VariadicDynCastAllOfMatcher
+    CUDAKernelCallExpr;
 
-/// \brief  Matches declaration that has CUDA global attribute.
-///
-/// Given
-/// \code
-///   __attribute__((global)) void f() { ... }
-/// \endcode
-/// matches the function declaration of f.
-AST_MATCHER(Decl, hasCudaGlobalAttr) {
-  return Node.hasAttr();
-}
-
 } // end namespace ast_matchers
 } // end namespace clang
 
Index: include/clang/ASTMatchers/ASTMatchersInternal.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchersInternal.h
+++ include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1658,6 +1658,28 @@
   ast_type_traits::DynTypedNode Node;
 };
 
+/// \brief Matches declarations have an attribute of type \c Attr
+template )>
+class HasAttrMatcher : public SingleNodeMatcherInterface {
+  static_assert(std::is_same::value,
+                "unsupported class for matcher");
+public:
+  typedef typename ExtractFunctionArgMeta::type ReturnTypes;
+  operator Matcher() const {
+    static_assert(TypeListContainsSuperOf::value,
+                  "right polymorphic conversion");
+    return Matcher(new HasAttrMatcher());
+  }
+  bool matchesNode(const T &Node) const override {
+    return matchesSpecialized(Node);
+  }
+private:
+  bool matchesSpecialized(const Decl &Node) const {
+    return Node.hasAttr();
+  }
+};
+
 } // end namespace internal
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -78,6 +78,7 @@
   //
   // Polymorphic + argument overload:
   // findAll
+  // hasAttr
   //
   // Other:
   // equals
@@ -182,9 +183,6 @@
   REGISTER_MATCHER(hasCaseConstant);
   REGISTER_MATCHER(hasCondition);
   REGISTER_MATCHER(hasConditionVariableStatement);
-  REGISTER_MATCHER(hasCudaDeviceAttr);
-  REGISTER_MATCHER(hasCudaGlobalAttr);
-  REGISTER_MATCHER(hasCudaHostAttr);
   REGISTER_MATCHER(hasDeclContext);
   REGISTER_MATCHER(hasDeclaration);
   REGISTER_MATCHER(hasDeducedType);
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ 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())));
+  EXPECT_FALSE(matches("struct X {};",
+                       decl(hasAttr())));
+}
+
 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()));
   EXPECT_TRUE(notMatchesWithCuda("void f() {}",
-                                 hasCudaGlobalAttr()));
+                                 CUDAKernelCallExpr()));
   EXPECT_FALSE(notMatchesWithCuda("__attribute__((global)) void f() {}",
-                                  hasCudaGlobalAttr()));
+                                  hasAttr()));
 }
 
 // Implements a run method that returns whether BoundNodes contains a