[PATCH] D52957: [analyzer] Teach CallEvent about C++17 aligned new.

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 04:51:48 PST 2020


steakhal added a comment.
Herald added subscribers: ASDenysPetrov, martong, Charusso, dkrupp.

I'm not sure if this implementation is correct.

I'm expecting this checker code not to crash:

  const auto *alloc = dyn_cast<CXXAllocatorCall>(&Call);
  if (!alloc)
    return;
  
  const int NumImpArgs = alloc->getNumImplicitArgs();
  errs() << "alloc->getNumImplicitArgs(): " << NumImpArgs << '\n'; // prints 1
  for (int i = 0; i < NumImpArgs; ++i)
    errs() << "> " << alloc->getPlacementArgExpr(i) << '\n'; // crash: assertion violated
  
  const int NumArgs = alloc->getNumArgs();
  errs() << "alloc->getNumArgs(): " << NumArgs << '\n';
  for (int i = NumImpArgs; i < NumArgs; ++i)
    errs() << "> " << alloc->getArgExpr(i) << '\n';

Analyzed code:

  void foo() {
    int *p = new int;
  }

Assertion:

  clang: ../../clang/include/clang/AST/ExprCXX.h:2272: clang::Expr* clang::CXXNewExpr::getPlacementArg(unsigned int): Assertion `(I < getNumPlacementArgs()) && "Index out of range!"' failed.



---

I'm planning to improve the `MallocChecker` using `CallEvent`s directly, instead of using the underlaying `CallExpr` or `CXXNewExpr` objects in `MallocChecker::checkCXXNewOrCXXDelete`.
Am I misusing something? @NoQ


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D52957/new/

https://reviews.llvm.org/D52957



More information about the cfe-commits mailing list