Skip to content

Commit

Permalink
Merging r293604:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
r293604 | sammccall | 2017-01-30 21:23:20 -0800 (Mon, 30 Jan 2017) | 12 lines

In VirtualCallChecker, handle indirect calls

Summary:
In VirtualCallChecker, handle indirect calls.

getDirectCallee() can be nullptr, and dyn_cast(nullptr) is UB

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D29303
------------------------------------------------------------------------

llvm-svn: 296154
  • Loading branch information
zmodem committed Feb 24, 2017
1 parent e6ba2e0 commit e6df079
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ void WalkAST::VisitCXXMemberCallExpr(CallExpr *CE) {
}

// 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());
Expand Down
11 changes: 11 additions & 0 deletions clang/test/Analysis/virtualcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,23 @@ class E final : public B {
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"
Expand Down

0 comments on commit e6df079

Please sign in to comment.