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

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 3 10:01:52 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)
----------------
PiotrZSL wrote:

Note: Avoid double calls to getMemoizationData (assign to some local variable and use or write), but still call to getMemoizationData should be in theory optimized.

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


More information about the cfe-commits mailing list