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

Loïc Joly via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 3 11:17:47 PST 2024


================
@@ -1237,7 +1237,8 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
           // Make sure we do not visit the same node twice.
           // Otherwise, we'll visit the common ancestors as often as there
           // are splits on the way down.
-          if (Visited.insert(Parent.getMemoizationData()).second)
+          if (Parent.getMemoizationData() == nullptr ||
+              Visited.insert(Parent.getMemoizationData()).second)
----------------
loic-joly-sonarsource wrote:

Since this is simply an if and taking an address, I assumed it would be optimized. But I applied the suggested change.

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


More information about the cfe-commits mailing list