[clang] 4cbea09 - [ASTMatchers] Fix segfault when Action is nullptr
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 5 07:17:40 PST 2021
Author: Stephen Kelly
Date: 2021-02-05T15:17:13Z
New Revision: 4cbea09431cd7d976770348d8e3d67cf1d3637e8
URL: https://github.com/llvm/llvm-project/commit/4cbea09431cd7d976770348d8e3d67cf1d3637e8
DIFF: https://github.com/llvm/llvm-project/commit/4cbea09431cd7d976770348d8e3d67cf1d3637e8.diff
LOG: [ASTMatchers] Fix segfault when Action is nullptr
It can be nullptr in unit tests.
Added:
Modified:
clang/lib/ASTMatchers/ASTMatchFinder.cpp
Removed:
################################################################################
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index 9be275a528eb..5d6cea54b8ec 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -1336,7 +1336,10 @@ MatchFinder::~MatchFinder() {}
void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
MatchCallback *Action) {
- if (auto TK = Action->getCheckTraversalKind())
+ llvm::Optional<TraversalKind> TK;
+ if (Action)
+ TK = Action->getCheckTraversalKind();
+ if (TK)
Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
else
Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
@@ -1351,7 +1354,10 @@ void MatchFinder::addMatcher(const TypeMatcher &NodeMatch,
void MatchFinder::addMatcher(const StatementMatcher &NodeMatch,
MatchCallback *Action) {
- if (auto TK = Action->getCheckTraversalKind())
+ llvm::Optional<TraversalKind> TK;
+ if (Action)
+ TK = Action->getCheckTraversalKind();
+ if (TK)
Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
else
Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
More information about the cfe-commits
mailing list