Skip to content

Commit ef47a0a

Browse files
committed
[Fix]"[-Wunsafe-buffer-usage] Add a new forEachDescendant matcher that skips callable declarations"
The original patch in commit b2ac5fd 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
1 parent 8641687 commit ef47a0a

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace llvm;
1515
using namespace clang;
1616
using namespace ast_matchers;
1717

18-
namespace clang::ast_matchers::internal {
18+
namespace clang::ast_matchers {
1919
// A `RecursiveASTVisitor` that traverses all descendants of a given node "n"
2020
// except for those belonging to a different callable of "n".
2121
class MatchDescendantVisitor
@@ -26,9 +26,10 @@ class MatchDescendantVisitor
2626
// Creates an AST visitor that matches `Matcher` on all
2727
// descendants of a given node "n" except for the ones
2828
// belonging to a different callable of "n".
29-
MatchDescendantVisitor(const DynTypedMatcher *Matcher, ASTMatchFinder *Finder,
30-
BoundNodesTreeBuilder *Builder,
31-
ASTMatchFinder::BindKind Bind)
29+
MatchDescendantVisitor(const internal::DynTypedMatcher *Matcher,
30+
internal::ASTMatchFinder *Finder,
31+
internal::BoundNodesTreeBuilder *Builder,
32+
internal::ASTMatchFinder::BindKind Bind)
3233
: Matcher(Matcher), Finder(Finder), Builder(Builder), Bind(Bind),
3334
Matches(false) {}
3435

@@ -86,32 +87,32 @@ class MatchDescendantVisitor
8687
// Returns 'true' if traversal should continue after this function
8788
// returns, i.e. if no match is found or 'Bind' is 'BK_All'.
8889
template <typename T> bool match(const T &Node) {
89-
BoundNodesTreeBuilder RecursiveBuilder(*Builder);
90+
internal::BoundNodesTreeBuilder RecursiveBuilder(*Builder);
9091

9192
if (Matcher->matches(DynTypedNode::create(Node), Finder,
9293
&RecursiveBuilder)) {
9394
ResultBindings.addMatch(RecursiveBuilder);
9495
Matches = true;
95-
if (Bind != ASTMatchFinder::BK_All)
96+
if (Bind != internal::ASTMatchFinder::BK_All)
9697
return false; // Abort as soon as a match is found.
9798
}
9899
return true;
99100
}
100101

101-
const DynTypedMatcher *const Matcher;
102-
ASTMatchFinder *const Finder;
103-
BoundNodesTreeBuilder *const Builder;
104-
BoundNodesTreeBuilder ResultBindings;
105-
const ASTMatchFinder::BindKind Bind;
102+
const internal::DynTypedMatcher *const Matcher;
103+
internal::ASTMatchFinder *const Finder;
104+
internal::BoundNodesTreeBuilder *const Builder;
105+
internal::BoundNodesTreeBuilder ResultBindings;
106+
const internal::ASTMatchFinder::BindKind Bind;
106107
bool Matches;
107108
};
108109

109-
AST_MATCHER_P(Stmt, forEveryDescendant, Matcher<Stmt>, innerMatcher) {
110+
AST_MATCHER_P(Stmt, forEveryDescendant, internal::Matcher<Stmt>, innerMatcher) {
110111
MatchDescendantVisitor Visitor(new DynTypedMatcher(innerMatcher), Finder,
111112
Builder, ASTMatchFinder::BK_All);
112113
return Visitor.findMatch(DynTypedNode::create(Node));
113114
}
114-
} // namespace clang::ast_matchers::internal
115+
} // namespace clang::ast_matchers
115116

116117
namespace {
117118
// Because the analysis revolves around variables and their types, we'll need to

0 commit comments

Comments
 (0)