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); }
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); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits