[clang] Optimize -Wunsafe-buffer-usage. (PR #124554)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 27 09:17:59 PST 2025
================
@@ -186,106 +205,202 @@ class MatchDescendantVisitor : public DynamicRecursiveASTVisitor {
return DynamicRecursiveASTVisitor::TraverseStmt(Node);
}
+ void set_ast_context(ASTContext &Context) { ActiveASTContext = &Context; }
+
+ void set_handler(const UnsafeBufferUsageHandler &NewHandler) {
+ Handler = &NewHandler;
+ }
+
private:
// Sets 'Matched' to true if 'Matcher' matches 'Node'
//
// 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) {
- internal::BoundNodesTreeBuilder RecursiveBuilder(*Builder);
-
- if (Matcher->matches(DynTypedNode::create(Node), Finder,
- &RecursiveBuilder)) {
- ResultBindings.addMatch(RecursiveBuilder);
+ if (Matcher->matches(DynTypedNode::create(Node), *ActiveASTContext,
+ *Handler)) {
Matches = true;
- if (Bind != internal::ASTMatchFinder::BK_All)
+ if (!BindAll)
return false; // Abort as soon as a match is found.
}
return true;
}
- const internal::DynTypedMatcher *const Matcher;
- internal::ASTMatchFinder *const Finder;
- internal::BoundNodesTreeBuilder *const Builder;
- internal::BoundNodesTreeBuilder ResultBindings;
- const internal::ASTMatchFinder::BindKind Bind;
+ CustomMatcher *const Matcher;
+ /// Defines how bindings are processed on recursive matches.
----------------
ilya-biryukov wrote:
NIT: `binding` is not really a concept we use anywhere else now that the matchers are gone.
Should this simply say "When false, finds the first match and stops. When true, finds all matches"?
https://github.com/llvm/llvm-project/pull/124554
More information about the cfe-commits
mailing list