Skip to content

Commit 702f822

Browse files
committed
[ASTMatcher] Avoid isImplicit call on object which could be nullptr
A callExpr whose argument is dependent has a null getCalleeDecl(). Differential Revision: https://reviews.llvm.org/D93324
1 parent bc7126b commit 702f822

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

clang/include/clang/ASTMatchers/ASTMatchersInternal.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,11 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
10641064
/// is \c NULL.
10651065
bool matchesDecl(const Decl *Node, ASTMatchFinder *Finder,
10661066
BoundNodesTreeBuilder *Builder) const {
1067-
if (Finder->isTraversalIgnoringImplicitNodes() && Node->isImplicit())
1068-
return false;
1069-
return Node != nullptr && this->InnerMatcher.matches(
1070-
DynTypedNode::create(*Node), Finder, Builder);
1067+
return Node != nullptr &&
1068+
!(Finder->isTraversalIgnoringImplicitNodes() &&
1069+
Node->isImplicit()) &&
1070+
this->InnerMatcher.matches(DynTypedNode::create(*Node), Finder,
1071+
Builder);
10711072
}
10721073
};
10731074

clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,18 @@ void bar()
19351935
matches(Code, callExpr(traverse(TK_IgnoreUnlessSpelledInSource,
19361936
hasAnyArgument(floatLiteral())))));
19371937

1938+
EXPECT_TRUE(matches(
1939+
R"cpp(
1940+
void takesBool(bool){}
1941+
1942+
template <typename T>
1943+
void neverInstantiatedTemplate() {
1944+
takesBool(T{});
1945+
}
1946+
)cpp",
1947+
traverse(TK_IgnoreUnlessSpelledInSource,
1948+
callExpr(unless(callExpr(hasDeclaration(functionDecl())))))));
1949+
19381950
EXPECT_TRUE(
19391951
matches(VarDeclCode, varDecl(traverse(TK_IgnoreUnlessSpelledInSource,
19401952
hasType(builtinType())))));

0 commit comments

Comments
 (0)