[LLVMdev] Checker for destruction-needing classes allocated in BumpPtrAllocators?

Ted Kremenek kremenek at apple.com
Fri Mar 19 12:59:57 PDT 2010


Hi Jeffrey,

The check in question checks that specific LLVM classes (and their subclasses) don't have fields that are SmallVector or std::vector.  It's basically a policy check on those classes; it doesn't know anything about BumpPtrAllocator itself.  The code for the check is located here:

  llvm/tools/clang/lib/Checker/LLVMConventionsChecker.cpp

It can be run on the LLVM codebase using scan-build:

  http://clang-analyzer.llvm.org/scan-build.html

When analyzing C++ code, you will need to:

(1) Define the environment variable CCC_ANALYZER_CPLUSPLUS to enable C++ analysis (I didn't want casual users trying it yet)

(2) Run scan-build with the -analyzer-check-llvm-conventions option.  For example:

$ export CCC_ANALYZER_CPLUSPLUS=1
$ scan-build <path/to/llvm/source>/configure
$ scan-build -analyzer-check-llvm-conventions -V make

Ted

On Mar 18, 2010, at 11:02 PM, Jeffrey Yasskin wrote:

> Hi Ted,
> 
> Doug said you might have a clang-based checker that would detect when
> people allocate memory with a BumpPtrAllocator and then construct a
> class into it that needs destruction. In killing valgrind-found memory
> leaks in LLVM, I've found several instances of this mistake. They
> often involve SmallVectors, which only show up as leaks in valgrind if
> they happen to overflow their static allocation, so it would be useful
> to also check this statically. Could you point me to any code you have
> for this?
> 
> Thanks,
> Jeffrey





More information about the llvm-dev mailing list