[PATCH] D105821: [analyzer] [WIP] Model destructor for std::unique_ptr

Deep Majumder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 25 22:01:00 PDT 2021


RedDocMD added a comment.

In D105821#2897006 <https://reviews.llvm.org/D105821#2897006>, @NoQ wrote:

>> the following code doesn't emit any warnings
>
> This code doesn't seem to have any `unique_ptr`s in it? It's not like you're modeling this custom class as well? Can you try the same with the actual `unique_ptr`?

The following code emits a warning for leaked memory:

  #include <memory>
  
  class Lame {
  	int *ptr;
  public:
  	explicit Lame(int *ptr) : ptr(ptr) {}
  	~Lame() { delete ptr; }
  };
  
  void foo() {
  	int *ptr = new int(13);
  	auto smart = std::make_unique<Lame>(ptr);
  	// No leak here
  }

It seems that there is a flaw in the way I was testing for warnings. 
Why does the following command not display the warnings? `./llvm/release/bin/clang -std=c++17 -Xclang -analyze -Xclang -analyzer-checker=core,cplusplus.Move,cplusplus.NewDelete,alpha.cplusplus.SmartPtr -Xclang -analyzer-output=text -Xclang -analyzer-config -Xclang cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true -c lame-class.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105821



More information about the cfe-commits mailing list