[PATCH] D18991: [ASTMatchers]: fix crash in hasReturnValue

Matthias Gehre via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 11 13:13:10 PDT 2016


mgehre created this revision.
mgehre added reviewers: klimek, alexfh.
mgehre added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

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.

http://reviews.llvm.org/D18991

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

Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -5500,6 +5500,7 @@
   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
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5015,6 +5015,8 @@
 ///   matching 'a + b'
 AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher<Expr>, 
               InnerMatcher) {
+  if (!Node.getRetValue())
+    return false;
   return InnerMatcher.matches(*Node.getRetValue(), Finder, Builder);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18991.53311.patch
Type: text/x-patch
Size: 1011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160411/e1978f51/attachment.bin>


More information about the cfe-commits mailing list