]> granicus.if.org Git - clang/commitdiff
[ASTMatchers]: fix crash in hasReturnValue
authorMatthias Gehre <M.Gehre@gmx.de>
Tue, 12 Apr 2016 05:43:18 +0000 (05:43 +0000)
committerMatthias Gehre <M.Gehre@gmx.de>
Tue, 12 Apr 2016 05:43:18 +0000 (05:43 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266043 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp

index 04d6938a2d9e8b89c8bdb4443c5ecc467e7b8374..9a89cd1e38189f4e7c1a1753d5efcf669a789d70 100644 (file)
@@ -5013,9 +5013,11 @@ AST_MATCHER_P(Decl, hasAttr, attr::Kind, AttrKind) {
 ///   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;
 }
 
 
index a34617935799a2968d556dbef3c0f7c5c6b98221..e4b6bb170331fa2d83a7ecefe9c7cdd281568351 100644 (file)
@@ -5500,6 +5500,7 @@ TEST(StatementMatcher, HasReturnValue) {
   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