Summary:
The crash was reproduced by the included test case. It was initially
found through a crash of clang-tidy's misc-misplaced-widening-cast
check.
Reviewers: klimek, alexfh
Subscribers: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D18991
llvm-svn: 266043
/// matches 'return a + b'
/// with binaryOperator()
/// matching 'a + b'
-AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher<Expr>,
+AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher<Expr>,
InnerMatcher) {
- return InnerMatcher.matches(*Node.getRetValue(), Finder, Builder);
+ if (const auto *RetValue = Node.getRetValue())
+ return InnerMatcher.matches(*RetValue, Finder, Builder);
+ return false;
}
StatementMatcher RetVal = returnStmt(hasReturnValue(binaryOperator()));
EXPECT_TRUE(matches("int F() { int a, b; return a + b; }", RetVal));
EXPECT_FALSE(matches("int F() { int a; return a; }", RetVal));
+ EXPECT_FALSE(matches("void F() { return; }", RetVal));
}
} // end namespace ast_matchers