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

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to