[llvm-branch-commits] [clang] 702f822 - [ASTMatcher] Avoid isImplicit call on object which could be nullptr
Stephen Kelly via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 15 15:31:49 PST 2020
Author: Stephen Kelly
Date: 2020-12-15T23:27:38Z
New Revision: 702f822ca5bbff96401e9ede39f4ae5c7cbc6b05
URL: https://github.com/llvm/llvm-project/commit/702f822ca5bbff96401e9ede39f4ae5c7cbc6b05
DIFF: https://github.com/llvm/llvm-project/commit/702f822ca5bbff96401e9ede39f4ae5c7cbc6b05.diff
LOG: [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
Added:
Modified:
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index fdc4f66f5d9c7..46de4093272d1 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1064,10 +1064,11 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
/// is \c NULL.
bool matchesDecl(const Decl *Node, ASTMatchFinder *Finder,
BoundNodesTreeBuilder *Builder) const {
- if (Finder->isTraversalIgnoringImplicitNodes() && Node->isImplicit())
- return false;
- return Node != nullptr && this->InnerMatcher.matches(
- DynTypedNode::create(*Node), Finder, Builder);
+ return Node != nullptr &&
+ !(Finder->isTraversalIgnoringImplicitNodes() &&
+ Node->isImplicit()) &&
+ this->InnerMatcher.matches(DynTypedNode::create(*Node), Finder,
+ Builder);
}
};
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 6f1ed0491ba1f..10d2d6ec3916a 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1935,6 +1935,18 @@ void bar()
matches(Code, callExpr(traverse(TK_IgnoreUnlessSpelledInSource,
hasAnyArgument(floatLiteral())))));
+ EXPECT_TRUE(matches(
+ R"cpp(
+void takesBool(bool){}
+
+template <typename T>
+void neverInstantiatedTemplate() {
+ takesBool(T{});
+}
+)cpp",
+ traverse(TK_IgnoreUnlessSpelledInSource,
+ callExpr(unless(callExpr(hasDeclaration(functionDecl())))))));
+
EXPECT_TRUE(
matches(VarDeclCode, varDecl(traverse(TK_IgnoreUnlessSpelledInSource,
hasType(builtinType())))));
More information about the llvm-branch-commits
mailing list