[clang] Fix a bug with the hasAncestor AST matcher when a node has several parents without pointer identity (PR #118511)

via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 3 08:25:42 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 57907c1a96e82c17b16111b919ab7c0f3d4370ab ed43bf26057073ba3f1b185838ba95048002980f --extensions cpp -- clang/lib/ASTMatchers/ASTMatchFinder.cpp clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index a7ef5ae694..78fbbddb6b 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1238,7 +1238,7 @@ private:
           // Otherwise, we'll visit the common ancestors as often as there
           // are splits on the way down.
           if (Parent.getMemoizationData() == nullptr ||
-            Visited.insert(Parent.getMemoizationData()).second)
+              Visited.insert(Parent.getMemoizationData()).second)
             Queue.push_back(Parent);
         }
         Queue.pop_front();
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 17b058e478..fdef08674d 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5537,8 +5537,8 @@ TEST(HasAncestor, MatchesInImplicitCode) {
 }
 
 TEST(HasAncestor, MatchesWithMultipleParentsWithoutPointerIdentity) {
-    EXPECT_TRUE(matches(
-    R"cpp(
+  EXPECT_TRUE(matches(
+      R"cpp(
 template <int i> class Fact {};
 template <class T> class W {};
 template <class T> struct A
@@ -5551,7 +5551,7 @@ void f() {
     A<int>::f();
     A<double>::f();
 })cpp",
-    integerLiteral(hasAncestor(functionDecl()))));
+      integerLiteral(hasAncestor(functionDecl()))));
 }
 
 TEST(HasParent, MatchesOnlyParent) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/118511


More information about the cfe-commits mailing list