[PATCH] D120949: [clang][AST matchers] adding attributedStmt AST matcher

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 28 14:56:45 PDT 2022


aaron.ballman added a comment.

Can you also add a release note for the changes?



================
Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:7800
+                          attr::Kind, AttrKind) {
+  return llvm::any_of(Node.getAttrs(),
+                      [&](const Attr *A) { return A->getKind() == AttrKind; });
----------------
Well this is awkward. :-D There's no way to check for whether the node has attributes for both kinds of nodes, but decl nodes requires that check; but there's no range-based for loop (or other iterator interface) that's the same on both nodes either.

I think you're going to need to add a class to `ASTMatchersInternal.h` to dispatch to the correct implementation for this query. You can look at how `HasSizeMatcher` is implemented and used to get an idea.


================
Comment at: clang/lib/AST/DeclBase.cpp:909
 const AttrVec &Decl::getAttrs() const {
-  assert(HasAttrs && "No attrs to get!");
   return getASTContext().getDeclAttrs(this);
----------------
I don't think it's valid to remove this assert (looking at the git blame for this and `ASTContext::getDeclAttrs()` shows this has all been the same for the past 12 years).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120949/new/

https://reviews.llvm.org/D120949



More information about the cfe-commits mailing list