Memory leaks after llvm_shutdown

Hi llvmdev!

In our project (Windows, Visual Studio compiler) we’ve got some frontend which generates LLVM IR. Now I’m observing strange llvm_shutdown behavior.

If I called it when I was done using the LLVM APIs I saw that destructors of static objects created new ManagedStatic objects, which was never freed.

Then I tried to use static global llvm_shutdown_obj to cause destruction of ManagedStatics after calling all static destructors. In that case I got “pure virtual function call” because of early release of BumpPtrAllocator::DefaultSlabAllocator.

Call stack for this case:
msvcr100d.dll!_purecall() Line 54 + 0x7 bytes C

llvm_test.exe!llvm::BumpPtrAllocator::DeallocateSlabs(llvm::MemSlab * Slab) Line 71 + 0x1b bytes C++
llvm_test.exe!llvm::BumpPtrAllocator::~BumpPtrAllocator() Line 30 C++
llvm_test.exe!llvm::LLVMContextImpl::~LLVMContextImpl() Line 128 + 0xf3 bytes C++
llvm_test.exe!llvm::LLVMContextImpl::scalar deleting destructor'() + 0x16 bytes C++ llvm_test.exe!llvm::LLVMContext::~LLVMContext() Line 62 + 0x38 bytes C++ llvm_test.exe!llvm::LLVMContext::scalar deleting destructor’() + 0x16 bytes C++
llvm_test.exe!llvm::object_deleterllvm::LLVMContext::call(void * Ptr) Line 32 + 0x37 bytes C++
llvm_test.exe!llvm::ManagedStaticBase::destroy() Line 68 + 0x10 bytes C++
llvm_test.exe!llvm::llvm_shutdown() Line 78 + 0xb bytes C++

Also I tried not to use GlobalContext object and created my own one. This method didn’t help - GlobalContext was still lazy creating by PseudoSourceValue ctor .

I would understand to know if I did something wrong or is this a bug?
I made tests both on 3.1 and trunk builds.

Thank you in advance!

example.cpp (1.58 KB)