Checker for destruction-needing classes allocated in BumpPtrAllocators?

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?


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:


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

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:

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