Allow types that have been forwarded to to be freed.
authorJeffrey Yasskin <jyasskin@google.com>
Sat, 13 Mar 2010 20:09:55 +0000 (20:09 +0000)
committerJeffrey Yasskin <jyasskin@google.com>
Sat, 13 Mar 2010 20:09:55 +0000 (20:09 +0000)
Tested: make check-lit && valgrind --dsymutil=yes --leak-check=full unittests/ExecutionEngine/JIT/Debug/JITTests

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

lib/VMCore/Type.cpp

index 9b2c2cab81fb30859bee8b9e3c291a7b41f87ba2..2a0cfa8470eae16ec54567a793c596c9bea55876 100644 (file)
@@ -87,6 +87,11 @@ void Type::destroy() const {
     pImpl->OpaqueTypes.erase(opaque_this);
   }
 
+  if (ForwardType && ForwardType->isAbstract()) {
+    ForwardType->dropRef();
+    ForwardType = NULL;
+  }
+
   // For all the other type subclasses, there is either no contained types or 
   // just one (all Sequentials). For Sequentials, the PATypeHandle is not
   // allocated past the type object, its included directly in the SequentialType
@@ -254,10 +259,12 @@ const Type *Type::getForwardedTypeInternal() const {
   // Yes, it is forwarded again.  First thing, add the reference to the new
   // forward type.
   if (RealForwardedType->isAbstract())
-    cast<DerivedType>(RealForwardedType)->addRef();
+    RealForwardedType->addRef();
 
   // Now drop the old reference.  This could cause ForwardType to get deleted.
-  cast<DerivedType>(ForwardType)->dropRef();
+  // ForwardType must be abstract because only abstract types can have their own
+  // ForwardTypes.
+  ForwardType->dropRef();
 
   // Return the updated type.
   ForwardType = RealForwardedType;
@@ -1142,8 +1149,8 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) {
   // Any PATypeHolders referring to this type will now automatically forward to
   // the type we are resolved to.
   ForwardType = NewType;
-  if (NewType->isAbstract())
-    cast<DerivedType>(NewType)->addRef();
+  if (ForwardType->isAbstract())
+    ForwardType->addRef();
 
   // Add a self use of the current type so that we don't delete ourself until
   // after the function exits.