This revision was automatically updated to reflect the committed changes. Closed by commit rC359530: [analyzer] SmartPtrModeling: Fix a null dereference. (authored by dergachev, committed by ).
Changed prior to commit: https://reviews.llvm.org/D61285?vs=197222&id=197251#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D61285/new/ https://reviews.llvm.org/D61285 Files: lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp test/Analysis/smart-ptr.cpp Index: test/Analysis/smart-ptr.cpp =================================================================== --- test/Analysis/smart-ptr.cpp +++ test/Analysis/smart-ptr.cpp @@ -16,3 +16,13 @@ // TODO: Report a null dereference (instead). *P.get() = 1; // expected-warning {{Method called on moved-from object 'P'}} } + +// Don't crash when attempting to model a call with unknown callee. +namespace testUnknownCallee { +struct S { + void foo(); +}; +void bar(S *s, void (S::*func)(void)) { + (s->*func)(); // no-crash +} +} // namespace testUnknownCallee Index: lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp +++ lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp @@ -39,7 +39,7 @@ // TODO: Handle other methods, such as .get() or .release(). // But once we do, we'd need a visitor to explain null dereferences // that are found via such modeling. - const auto *CD = dyn_cast<CXXConversionDecl>(Call->getDecl()); + const auto *CD = dyn_cast_or_null<CXXConversionDecl>(Call->getDecl()); return CD && CD->getConversionType()->isBooleanType(); }
Index: test/Analysis/smart-ptr.cpp =================================================================== --- test/Analysis/smart-ptr.cpp +++ test/Analysis/smart-ptr.cpp @@ -16,3 +16,13 @@ // TODO: Report a null dereference (instead). *P.get() = 1; // expected-warning {{Method called on moved-from object 'P'}} } + +// Don't crash when attempting to model a call with unknown callee. +namespace testUnknownCallee { +struct S { + void foo(); +}; +void bar(S *s, void (S::*func)(void)) { + (s->*func)(); // no-crash +} +} // namespace testUnknownCallee Index: lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp +++ lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp @@ -39,7 +39,7 @@ // TODO: Handle other methods, such as .get() or .release(). // But once we do, we'd need a visitor to explain null dereferences // that are found via such modeling. - const auto *CD = dyn_cast<CXXConversionDecl>(Call->getDecl()); + const auto *CD = dyn_cast_or_null<CXXConversionDecl>(Call->getDecl()); return CD && CD->getConversionType()->isBooleanType(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits