Commit 7d2f60d3 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r293604:

------------------------------------------------------------------------
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
------------------------------------------------------------------------


git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_40@296154 91177308-0d34-0410-b5e6-96231b3b80d8
parent 7aee01dd
......@@ -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());
......
......@@ -115,12 +115,23 @@ public:
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"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment