Author: 5chmidti Date: 2023-10-16T14:09:46-04:00 New Revision: 5b07de1a5faf4a22ae6fd982b877c5e7e3a76559
URL: https://github.com/llvm/llvm-project/commit/5b07de1a5faf4a22ae6fd982b877c5e7e3a76559 DIFF: https://github.com/llvm/llvm-project/commit/5b07de1a5faf4a22ae6fd982b877c5e7e3a76559.diff LOG: [clang][ASTMatcher] fix hasAnyBase not binding submatchers (#67939) The BoundNodesTreeBuilder used in the BaseSpecMatcher was the original and was reset to its original state if a match occurred. The matcher now uses the local copy in the inner matcher. Fixes https://github.com/llvm/llvm-project/issues/65421 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/ASTMatchers/ASTMatchersInternal.cpp clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9782c123f4c9372..58c06edb6deeaf8 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -521,6 +521,8 @@ Bug Fixes to AST Handling computed RecordLayout is incorrect if fields are not completely imported and should not be cached. `Issue 64170 <https://github.com/llvm/llvm-project/issues/64170>`_ +- Fixed ``hasAnyBase`` not binding nodes in its submatcher. + (`#65421 <https://github.com/llvm/llvm-project/issues/65421>`_) Miscellaneous Bug Fixes ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp index 40688107215f287..435bbdeda22066e 100644 --- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -87,7 +87,7 @@ bool matchesAnyBase(const CXXRecordDecl &Node, [Finder, Builder, &BaseSpecMatcher](const CXXBaseSpecifier *BaseSpec, CXXBasePath &IgnoredParam) { BoundNodesTreeBuilder Result(*Builder); - if (BaseSpecMatcher.matches(*BaseSpec, Finder, Builder)) { + if (BaseSpecMatcher.matches(*BaseSpec, Finder, &Result)) { *Builder = std::move(Result); return true; } diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index 89954711804aa57..d4a695b974bf0e5 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -8,6 +8,7 @@ #include "ASTMatchersTest.h" #include "clang/AST/Attrs.inc" +#include "clang/AST/DeclCXX.h" #include "clang/AST/PrettyPrinter.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/ASTMatchers/ASTMatchers.h" @@ -5457,6 +5458,18 @@ TEST(HasParent, NoDuplicateParents) { stmt().bind("node"), std::make_unique<HasDuplicateParents>())); } +TEST(HasAnyBase, BindsInnerBoundNodes) { + EXPECT_TRUE(matchAndVerifyResultTrue( + "struct Inner {}; struct Proxy : Inner {}; struct Main : public " + "Proxy {};", + cxxRecordDecl(hasName("Main"), + hasAnyBase(cxxBaseSpecifier(hasType( + cxxRecordDecl(hasName("Inner")).bind("base-class"))))) + .bind("class"), + std::make_unique<VerifyIdIsBoundTo<CXXRecordDecl>>("base-class", + "Inner"))); +} + TEST(TypeMatching, PointeeTypes) { EXPECT_TRUE(matches("int b; int &a = b;", referenceType(pointee(builtinType())))); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits