llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-analysis <details> <summary>Changes</summary> The additions to the test trigger crashes without the fixes. --- Full diff: https://github.com/llvm/llvm-project/pull/66742.diff 2 Files Affected: - (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+4-1) - (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+9) ``````````diff diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index 26e097349057238..98128693e145da4 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -289,11 +289,14 @@ static void insertIfFunction(const Decl &D, } static MemberExpr *getMemberForAccessor(const CXXMemberCallExpr &C) { + if (!C.getMethodDecl()) + return nullptr; auto *Body = dyn_cast_or_null<CompoundStmt>(C.getMethodDecl()->getBody()); if (!Body || Body->size() != 1) return nullptr; if (auto *RS = dyn_cast<ReturnStmt>(*Body->body_begin())) - return dyn_cast<MemberExpr>(RS->getRetValue()->IgnoreParenImpCasts()); + if (RS->getRetValue() != nullptr) + return dyn_cast<MemberExpr>(RS->getRetValue()->IgnoreParenImpCasts()); return nullptr; } diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index 14188f5acd5b36e..e8cbca756460369 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -1463,6 +1463,7 @@ TEST(TransferTest, StructModeledFieldsWithAccessor) { int getIntNotAccessed() const { return IntNotAccessed; } int getIntNoDefinition() const; int &getIntRef() { return IntRef; } + void returnVoid() const { return; } }; void target() { @@ -1473,6 +1474,14 @@ TEST(TransferTest, StructModeledFieldsWithAccessor) { int i2 = s.getWithInc(1); int i3 = s.getIntNoDefinition(); int &iref = s.getIntRef(); + + // Regression test: Don't crash on an indirect call (which doesn't have + // an associated `CXXMethodDecl`). + auto ptr_to_member_fn = &S::getPtr; + p1 = (s.*ptr_to_member_fn)(); + + // Regression test: Don't crash on a return statement without a value. + s.returnVoid(); // [[p]] } )"; `````````` </details> https://github.com/llvm/llvm-project/pull/66742 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits