[llvm] r210717 - Don't acquire the mutex during the destructor of PassRegistry.

Zachary Turner zturner at google.com
Wed Jun 11 16:03:31 PDT 2014

Author: zturner
Date: Wed Jun 11 18:03:31 2014
New Revision: 210717

URL: http://llvm.org/viewvc/llvm-project?rev=210717&view=rev
Don't acquire the mutex during the destructor of PassRegistry.

This destructor is run as part of static program termination, and
so all ManagedStatics (including this lock) will have been
destroyed by llvm_shutdown.  Furthermore, if there is actually
a race condition during static program termination, then we are
just hiding a bug somewhere else, because other threads should
not be running at this point.


Modified: llvm/trunk/lib/IR/PassRegistry.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/PassRegistry.cpp?rev=210717&r1=210716&r2=210717&view=diff
--- llvm/trunk/lib/IR/PassRegistry.cpp (original)
+++ llvm/trunk/lib/IR/PassRegistry.cpp Wed Jun 11 18:03:31 2014
@@ -73,7 +73,10 @@ void *PassRegistry::getImpl() const {
 PassRegistry::~PassRegistry() {
-  sys::SmartScopedWriter<true> Guard(*Lock);
+  // Don't acquire the mutex here.  This is destroyed during static execution of
+  // static destructors, after llvm_shutdown() has been called, so all instances
+  // of all ManagedStatics (including the Mutex), will have been destroyed as
+  // well.
   PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(pImpl);
   delete Impl;
   pImpl = nullptr;

More information about the llvm-commits mailing list