This revision was automatically updated to reflect the committed changes. Closed by commit rL293604: In VirtualCallChecker, handle indirect calls (authored by sammccall).
Changed prior to commit: https://reviews.llvm.org/D29303?vs=86342&id=86385#toc Repository: rL LLVM https://reviews.llvm.org/D29303 Files: cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp cfe/trunk/test/Analysis/virtualcall.cpp Index: cfe/trunk/test/Analysis/virtualcall.cpp =================================================================== --- cfe/trunk/test/Analysis/virtualcall.cpp +++ cfe/trunk/test/Analysis/virtualcall.cpp @@ -115,12 +115,23 @@ int foo() override; }; +// Regression test: don't crash when there's no direct callee. +class F { +public: + F() { + void (F::* ptr)() = &F::foo; + (this->*ptr)(); + } + void foo(); +}; + int main() { A *a; B *b; C *c; D *d; E *e; + F *f; } #include "virtualcall.h" Index: cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp +++ cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp @@ -179,7 +179,8 @@ } // Get the callee. - const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CE->getDirectCallee()); + const CXXMethodDecl *MD = + dyn_cast_or_null<CXXMethodDecl>(CE->getDirectCallee()); if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr<FinalAttr>() && !MD->getParent()->hasAttr<FinalAttr>()) ReportVirtualCall(CE, MD->isPure());
Index: cfe/trunk/test/Analysis/virtualcall.cpp =================================================================== --- cfe/trunk/test/Analysis/virtualcall.cpp +++ cfe/trunk/test/Analysis/virtualcall.cpp @@ -115,12 +115,23 @@ int foo() override; }; +// Regression test: don't crash when there's no direct callee. +class F { +public: + F() { + void (F::* ptr)() = &F::foo; + (this->*ptr)(); + } + void foo(); +}; + int main() { A *a; B *b; C *c; D *d; E *e; + F *f; } #include "virtualcall.h" Index: cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp +++ cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp @@ -179,7 +179,8 @@ } // Get the callee. - const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CE->getDirectCallee()); + const CXXMethodDecl *MD = + dyn_cast_or_null<CXXMethodDecl>(CE->getDirectCallee()); if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr<FinalAttr>() && !MD->getParent()->hasAttr<FinalAttr>()) ReportVirtualCall(CE, MD->isPure());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits