diff --git a/llvm/lib/Support/ManagedStatic.cpp b/llvm/lib/Support/ManagedStatic.cpp --- a/llvm/lib/Support/ManagedStatic.cpp +++ b/llvm/lib/Support/ManagedStatic.cpp @@ -27,6 +27,13 @@ static std::recursive_mutex *getManagedStaticMutex() { llvm::call_once(mutex_init_flag, initializeMutex); + // corner case handling - for tests purposes + // [this 'if' will not be triggered in real world app] + // it is for covering test case where RegisterManagedStatic + // is called AFTER llvm_shutdown + if (ManagedStaticMutex == nullptr) { + initializeMutex(); + } return ManagedStaticMutex; } @@ -76,8 +83,12 @@ /// llvm_shutdown - Deallocate and destroy all ManagedStatic variables. void llvm::llvm_shutdown() { - std::lock_guard Lock(*getManagedStaticMutex()); + { + std::lock_guard Lock(*getManagedStaticMutex()); - while (StaticList) - StaticList->destroy(); + while (StaticList) + StaticList->destroy(); + } + delete ManagedStaticMutex; + ManagedStaticMutex = nullptr; }