diff --git a/llvm/include/llvm/Value.h b/llvm/include/llvm/Value.h index b1db1ce3e1ee8831c1923c410f481a88ccac0a73..a7f8774e036f82033c5f5e04fd993f0ffaf04755 100644 --- a/llvm/include/llvm/Value.h +++ b/llvm/include/llvm/Value.h @@ -38,7 +38,7 @@ class TypeSymbolTable; template<typename ValueTy> class StringMapEntry; template <typename ValueTy = Value> class AssertingVH; -typedef StringMapEntry<Value*> ValueName; +typedef StringMapEntry<AssertingVH<> > ValueName; class raw_ostream; class AssemblyAnnotationWriter; class ValueHandleBase; diff --git a/llvm/include/llvm/ValueSymbolTable.h b/llvm/include/llvm/ValueSymbolTable.h index 4f8ebe800172a1b30a879753eef10f36170b8d79..9b4ccbaf8f30121416548dc437aeba42f2ba8d07 100644 --- a/llvm/include/llvm/ValueSymbolTable.h +++ b/llvm/include/llvm/ValueSymbolTable.h @@ -17,6 +17,7 @@ #include "llvm/Value.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/DataTypes.h" +#include "llvm/Support/ValueHandle.h" namespace llvm { template<typename ValueSubClass, typename ItemParentClass> @@ -44,7 +45,7 @@ class ValueSymbolTable { /// @{ public: /// @brief A mapping of names to values. - typedef StringMap<Value*> ValueMap; + typedef StringMap<AssertingVH<> > ValueMap; /// @brief An iterator over a ValueMap. typedef ValueMap::iterator iterator; diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 4b9251639544d4c5312d25294939167ad706b8d4..724e1aeb15c96cb5d6b369cf315fcb27fc70a0d4 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1083,7 +1083,7 @@ static void WriteValueSymbolTable(const ValueSymbolTable &VST, // VST_ENTRY: [valueid, namechar x N] // VST_BBENTRY: [bbid, namechar x N] unsigned Code; - if (isa<BasicBlock>(SI->getValue())) { + if (isa<BasicBlock>(*SI->getValue())) { Code = bitc::VST_CODE_BBENTRY; if (isChar6) AbbrevToUse = VST_BBENTRY_6_ABBREV; diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp index 2cdd55217cc4133c1af6495513b7c0073e4db3aa..8710b9461e89f43755ae5a80a4aa1c0fbf3a8d80 100644 --- a/llvm/lib/VMCore/Value.cpp +++ b/llvm/lib/VMCore/Value.cpp @@ -57,6 +57,14 @@ Value::Value(const Type *ty, unsigned scid) } Value::~Value() { + // If this value is named, destroy the name. This should not be in a symtab + // at this point. + if (Name) + Name->Destroy(); + + // There should be no uses of this object anymore, remove it. + LeakDetector::removeGarbageObject(this); + // Notify all ValueHandles (if present) that this value is going away. if (HasValueHandle) ValueHandleBase::ValueIsDeleted(this); @@ -76,14 +84,6 @@ Value::~Value() { } #endif assert(use_empty() && "Uses remain when a value is destroyed!"); - - // If this value is named, destroy the name. This should not be in a symtab - // at this point. - if (Name) - Name->Destroy(); - - // There should be no uses of this object anymore, remove it. - LeakDetector::removeGarbageObject(this); } /// hasNUses - Return true if this Value has exactly N users.