Index: include/llvm/Support/ManagedStatic.h =================================================================== --- include/llvm/Support/ManagedStatic.h +++ include/llvm/Support/ManagedStatic.h @@ -85,6 +85,14 @@ /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables. void llvm_shutdown(); +/// Purpose of this function is to free memory allocated for ManagedStaticMutex. +/// One might want to do that to avoid memory leaks in case LLVM is loaded as a +/// shared library (or dll) at runtime. +/// This function is not thread safe and should be called only if there are no +/// threads which are using the mutex now or will use the mutex in the future. +/// This means deleteManagedStaticMutex can be called only after llvm_shutdown. +void deleteManagedStaticMutex(); + /// llvm_shutdown_obj - This is a simple helper class that calls /// llvm_shutdown() when it is destroyed. struct llvm_shutdown_obj { Index: lib/Support/ManagedStatic.cpp =================================================================== --- lib/Support/ManagedStatic.cpp +++ lib/Support/ManagedStatic.cpp @@ -83,3 +83,8 @@ while (StaticList) StaticList->destroy(); } + +void llvm::deleteManagedStaticMutex() { + assert(StaticList == nullptr && "llvm_shutdown() must be called first!"); + delete ManagedStaticMutex; +} \ No newline at end of file