Fix an order-of-deallocation issue where the AttrListImpl could be deallocated before...
authorOwen Anderson <resistor@mac.com>
Thu, 18 Nov 2010 18:59:13 +0000 (18:59 +0000)
committerOwen Anderson <resistor@mac.com>
Thu, 18 Nov 2010 18:59:13 +0000 (18:59 +0000)
LLVMContext, causing memory errors.  Patch by Peter Collingbourne.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119721 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Attributes.cpp

index 477111a3ae8b427f3ad71c5465b5fb2068b78f07..e4a228b8c62c110fa60953effadaeabbb10e222a 100644 (file)
@@ -106,6 +106,11 @@ Attributes Attribute::typeIncompatible(const Type *Ty) {
 // AttributeListImpl Definition
 //===----------------------------------------------------------------------===//
 
+namespace llvm {
+  class AttributeListImpl;
+}
+
+static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
 
 namespace llvm {
 static ManagedStatic<sys::SmartMutex<true> > ALMutex;
@@ -131,6 +136,8 @@ public:
   }
   void DropRef() {
     sys::SmartScopedLock<true> Lock(*ALMutex);
+    if (!AttributesLists.isConstructed())
+      return;
     sys::cas_flag new_val = --RefCount;
     if (new_val == 0)
       delete this;
@@ -147,8 +154,6 @@ public:
 };
 }
 
-static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
-
 AttributeListImpl::~AttributeListImpl() {
   // NOTE: Lock must be acquired by caller.
   AttributesLists->RemoveNode(this);