[Fix][-Wunsafe-buffer-usage] Add a new `forEachDescendant` matcher that skips callabl...
authorziqingluo-90 <ziqing@udel.edu>
Fri, 6 Jan 2023 20:30:11 +0000 (12:30 -0800)
committerziqingluo-90 <ziqing@udel.edu>
Fri, 6 Jan 2023 20:32:35 +0000 (12:32 -0800)
The original patch does include a `new` statement without a matching
`delete`, causing Sanitizer warnings in
https://lab.llvm.org/buildbot/#/builders/5/builds/30522/steps/13/logs/stdio.

This commit is a fix to it.

Differential Revision: https://reviews.llvm.org/D138329

clang/lib/Analysis/UnsafeBufferUsage.cpp

index d941cf5..f03fe75 100644 (file)
@@ -26,7 +26,7 @@ public:
   // Creates an AST visitor that matches `Matcher` on all
   // descendants of a given node "n" except for the ones
   // belonging to a different callable of "n".
-  MatchDescendantVisitor(const internal::DynTypedMatcher *Matcher,
+  MatchDescendantVisitor(const internal::DynTypedMatcher &Matcher,
                          internal::ASTMatchFinder *Finder,
                          internal::BoundNodesTreeBuilder *Builder,
                          internal::ASTMatchFinder::BindKind Bind)
@@ -89,7 +89,7 @@ private:
   template <typename T> bool match(const T &Node) {
     internal::BoundNodesTreeBuilder RecursiveBuilder(*Builder);
 
-    if (Matcher->matches(DynTypedNode::create(Node), Finder,
+    if (Matcher.matches(DynTypedNode::create(Node), Finder,
                          &RecursiveBuilder)) {
       ResultBindings.addMatch(RecursiveBuilder);
       Matches = true;
@@ -99,7 +99,7 @@ private:
     return true;
   }
 
-  const internal::DynTypedMatcher *const Matcher;
+  const internal::DynTypedMatcher & Matcher;
   internal::ASTMatchFinder *const Finder;
   internal::BoundNodesTreeBuilder *const Builder;
   internal::BoundNodesTreeBuilder ResultBindings;
@@ -108,7 +108,7 @@ private:
 };
 
 AST_MATCHER_P(Stmt, forEveryDescendant, internal::Matcher<Stmt>, innerMatcher) {
-  MatchDescendantVisitor Visitor(new DynTypedMatcher(innerMatcher), Finder,
+  MatchDescendantVisitor Visitor(DynTypedMatcher(innerMatcher), Finder,
                                  Builder, ASTMatchFinder::BK_All);
   return Visitor.findMatch(DynTypedNode::create(Node));
 }