PHI nodes are not allowed to exist with zero incoming values, check that
[oota-llvm.git] / lib / VMCore / Value.cpp
index da3d87f9d2e7b7c4d623b7630a1767db3e738e33..402171be36ab10a421c801f018ef7e14b492a955 100644 (file)
@@ -7,6 +7,7 @@
 #include "llvm/InstrTypes.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
+#include "Support/LeakDetector.h"
 #include <algorithm>
 
 //===----------------------------------------------------------------------===//
@@ -18,7 +19,7 @@ static inline const Type *checkType(const Type *Ty) {
   return Ty;
 }
 
-Value::Value(const Type *ty, ValueTy vty, const std::string &name = "")
+Value::Value(const Type *ty, ValueTy vty, const std::string &name)
   : Name(name), Ty(checkType(ty), this) {
   VTy = vty;
 }
@@ -33,14 +34,15 @@ Value::~Value() {
   //
   if (Uses.begin() != Uses.end()) {
     std::cerr << "While deleting: " << Ty << "%" << Name << "\n";
-    for (use_const_iterator I = Uses.begin(); I != Uses.end(); ++I) {
-      std::cerr << "Use still stuck around after Def is destroyed:";
-      (*I)->dump();
-      std::cerr << "\n";
-    }
+    for (use_const_iterator I = Uses.begin(); I != Uses.end(); ++I)
+      std::cerr << "Use still stuck around after Def is destroyed:"
+                << **I << "\n";
   }
 #endif
   assert(Uses.begin() == Uses.end());
+
+  // There should be no uses of this object anymore, remove it.
+  LeakDetector::removeGarbageObject(this);
 }
 
 void Value::replaceAllUsesWith(Value *D) {
@@ -56,12 +58,8 @@ void Value::replaceAllUsesWith(Value *D) {
     Use->replaceUsesOfWith(this, D);
 
 #ifndef NDEBUG      // only in -g mode...
-    if (Uses.size() == NumUses) {
-      std::cerr << "Use: ";
-      Use->dump();
-      std::cerr << "replace with: ";
-      D->dump(); 
-    }
+    if (Uses.size() == NumUses)
+      std::cerr << "Use: " << *Use << "replace with: " << *D;
 #endif
     assert(Uses.size() != NumUses && "Didn't remove definition!");
   }
@@ -73,7 +71,7 @@ void Value::replaceAllUsesWith(Value *D) {
 // change Ty to point to the right type.  :)
 //
 void Value::refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
-  assert(Ty.get() == OldTy &&"Can't refine anything but my type!");
+  assert(Ty.get() == OldTy && "Can't refine anything but my type!");
   if (OldTy == NewTy && !OldTy->isAbstract())
     Ty.removeUserFromConcrete();
   Ty = NewTy;