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

Alister Johnson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 25 15:11:30 PDT 2022


ajohnson-uoregon updated this revision to Diff 418338.
ajohnson-uoregon added a comment.

I overloaded hasAttr and had to fix a couple CUDA tests to explicitly use the decl overload (the other tests 
for hasAttr did this already, so I think it was just a mistake in those tests).

I also had to remove an assert from Decl::getAttrs in DeclBase.cpp that checked if there were actually attributes 
on that decl to make the overload work (when I wrote the overload, I made both use getAttrs because AttributedStmts 
don't have attrs() like Decls do). After trawling git blame a bit, it looks like that assert was added way 
back in like 2010 when ASTContext::getDeclAttrs just did a straight lookup in the DeclAttrs map, which 
presumably would have done bad things if the decl had no attrs. In this commit though 
https://github.com/llvm/llvm-project/commit/561eceb4c4a20280d5324c873ddad1940960b891 that got fixed, so 
getDeclAttrs will return a new empty AttrVec if the lookup fails. The assert is not necessary since that commit, 
but I guess no one realized they could remove the assert.

tl;dr That assert broke lots of the old hasAttr tests for Decls that were now using getAttrs() instead of attrs(), 
and removing it fixes them, and since it's no longer needed I think it's okay to get rid of it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120949

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/DeclBase.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120949.418338.patch
Type: text/x-patch
Size: 9899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220325/9c1ebcd2/attachment-0001.bin>


More information about the cfe-commits mailing list