[PATCH] D124845: StaticAnalyzer should inline overridden delete operator the same way as overridden new operator

Fred Tingaud via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 3 05:20:13 PDT 2022


frederic-tingaud-sonarsource created this revision.
frederic-tingaud-sonarsource added a reviewer: dcoughlin.
Herald added subscribers: manas, ASDenysPetrov, martong, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
Herald added a project: All.
frederic-tingaud-sonarsource requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently, when encountering an overridden new operator, the StaticAnalyzer will inline it when possible, while an overridden delete operator will never be, which leads us to false positives like the following:

  struct CustomOperators {
    void *operator new(size_t count) {
      return malloc(count);
    }
  
    void operator delete(void *addr) {
      free(addr);
    }
  };
  
  void compliant() {
    auto *a = new CustomOperators();
    delete a; // warning{{Potential leak of memory pointed to by 'a'}}
  }

This patch restores the symmetry between how operator new and operator delete are handled by also inlining the content of operator delete when possible.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124845

Files:
  clang/include/clang/Analysis/ConstructionContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/test/Analysis/cxxnewexpr-callback-inline.cpp
  clang/test/Analysis/cxxnewexpr-callback-noinline.cpp
  clang/test/Analysis/dtor.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124845.426656.patch
Type: text/x-patch
Size: 6180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220503/8d1b9cfc/attachment-0001.bin>


More information about the cfe-commits mailing list