[clang] ef47a0a - [Fix]"[-Wunsafe-buffer-usage] Add a new `forEachDescendant` matcher that skips callable declarations"

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 5 12:04:46 PST 2023


Author: ziqingluo-90
Date: 2023-01-05T12:04:13-08:00
New Revision: ef47a0a711f12add401394f7af07a0b4d1635b56

URL: https://github.com/llvm/llvm-project/commit/ef47a0a711f12add401394f7af07a0b4d1635b56
DIFF: https://github.com/llvm/llvm-project/commit/ef47a0a711f12add401394f7af07a0b4d1635b56.diff

LOG: [Fix]"[-Wunsafe-buffer-usage] Add a new `forEachDescendant` matcher that skips callable declarations"

The original patch in commit b2ac5fd724c44cf662caed84bd8f84af574b981d
causes compilation errors which can be reproduced by the
`-fdelayed-template-parsing` flag.  This commit fixes the problem.

Related differential revision: https://reviews.llvm.org/D138329

Added: 
    

Modified: 
    clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 29c8dbb45fe9f..80a54c3ad38b7 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -15,7 +15,7 @@ using namespace llvm;
 using namespace clang;
 using namespace ast_matchers;
 
-namespace clang::ast_matchers::internal {
+namespace clang::ast_matchers {
 // A `RecursiveASTVisitor` that traverses all descendants of a given node "n"
 // except for those belonging to a 
diff erent callable of "n".
 class MatchDescendantVisitor
@@ -26,9 +26,10 @@ class MatchDescendantVisitor
   // Creates an AST visitor that matches `Matcher` on all
   // descendants of a given node "n" except for the ones
   // belonging to a 
diff erent callable of "n".
-  MatchDescendantVisitor(const DynTypedMatcher *Matcher, ASTMatchFinder *Finder,
-                         BoundNodesTreeBuilder *Builder,
-                         ASTMatchFinder::BindKind Bind)
+  MatchDescendantVisitor(const internal::DynTypedMatcher *Matcher,
+                         internal::ASTMatchFinder *Finder,
+                         internal::BoundNodesTreeBuilder *Builder,
+                         internal::ASTMatchFinder::BindKind Bind)
       : Matcher(Matcher), Finder(Finder), Builder(Builder), Bind(Bind),
         Matches(false) {}
 
@@ -86,32 +87,32 @@ class MatchDescendantVisitor
   // Returns 'true' if traversal should continue after this function
   // returns, i.e. if no match is found or 'Bind' is 'BK_All'.
   template <typename T> bool match(const T &Node) {
-    BoundNodesTreeBuilder RecursiveBuilder(*Builder);
+    internal::BoundNodesTreeBuilder RecursiveBuilder(*Builder);
 
     if (Matcher->matches(DynTypedNode::create(Node), Finder,
                          &RecursiveBuilder)) {
       ResultBindings.addMatch(RecursiveBuilder);
       Matches = true;
-      if (Bind != ASTMatchFinder::BK_All)
+      if (Bind != internal::ASTMatchFinder::BK_All)
         return false; // Abort as soon as a match is found.
     }
     return true;
   }
 
-  const DynTypedMatcher *const Matcher;
-  ASTMatchFinder *const Finder;
-  BoundNodesTreeBuilder *const Builder;
-  BoundNodesTreeBuilder ResultBindings;
-  const ASTMatchFinder::BindKind Bind;
+  const internal::DynTypedMatcher *const Matcher;
+  internal::ASTMatchFinder *const Finder;
+  internal::BoundNodesTreeBuilder *const Builder;
+  internal::BoundNodesTreeBuilder ResultBindings;
+  const internal::ASTMatchFinder::BindKind Bind;
   bool Matches;
 };
 
-AST_MATCHER_P(Stmt, forEveryDescendant, Matcher<Stmt>, innerMatcher) {
+AST_MATCHER_P(Stmt, forEveryDescendant, internal::Matcher<Stmt>, innerMatcher) {
   MatchDescendantVisitor Visitor(new DynTypedMatcher(innerMatcher), Finder,
                                  Builder, ASTMatchFinder::BK_All);
   return Visitor.findMatch(DynTypedNode::create(Node));
 }
-} // namespace clang::ast_matchers::internal
+} // namespace clang::ast_matchers
 
 namespace {
 // Because the analysis revolves around variables and their types, we'll need to


        


More information about the cfe-commits mailing list