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

llvm-svn: 296154
parent e6ba2e0c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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());
+11 −0
Original line number Diff line number Diff line
@@ -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"