Changes For Bug 352
[oota-llvm.git] / lib / VMCore / Value.cpp
index 9022e914c92d1df70fb951be7ce244663fbb5f56..60be53db5b6ad6fe9b3346a244dae97172c1eb79 100644 (file)
@@ -15,7 +15,8 @@
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constant.h"
-#include "Support/LeakDetector.h"
+#include "llvm/GlobalValue.h"
+#include "llvm/Support/LeakDetector.h"
 #include <algorithm>
 #include <iostream>
 using namespace llvm;
@@ -32,8 +33,11 @@ static inline const Type *checkType(const Type *Ty) {
 Value::Value(const Type *ty, unsigned scid, const std::string &name)
   : SubclassID(scid), Ty(checkType(ty)), Name(name) {
   if (!isa<Constant>(this) && !isa<BasicBlock>(this))
-    assert((Ty->isFirstClassType() || Ty == Type::VoidTy) &&
+    assert((Ty->isFirstClassType() || Ty == Type::VoidTy || 
+           isa<OpaqueType>(ty)) &&
            "Cannot create non-first-class values except for constants!");
+  if (ty == Type::VoidTy)
+    assert(name.empty() && "Cannot have named void values!");
 }
 
 Value::~Value() {
@@ -70,7 +74,10 @@ void Value::uncheckedReplaceAllUsesWith(Value *New) {
     // Must handle Constants specially, we cannot call replaceUsesOfWith on a
     // constant!
     if (Constant *C = dyn_cast<Constant>(U.getUser())) {
-      C->replaceUsesOfWithOnConstant(this, New, true);
+      if (!isa<GlobalValue>(C))
+        C->replaceUsesOfWithOnConstant(this, New, true);
+      else 
+        U.set(New);
     } else {
       U.set(New);
     }
@@ -96,7 +103,7 @@ void Value::replaceAllUsesWith(Value *New) {
 void User::replaceUsesOfWith(Value *From, Value *To) {
   if (From == To) return;   // Duh what?
 
-  assert(!isa<Constant>(this) &&
+  assert(!isa<Constant>(this) || isa<GlobalValue>(this) &&
          "Cannot call User::replaceUsesofWith on a constant!");
 
   for (unsigned i = 0, E = getNumOperands(); i != E; ++i)
@@ -107,3 +114,4 @@ void User::replaceUsesOfWith(Value *From, Value *To) {
       setOperand(i, To); // Fix it now...
     }
 }
+