#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;
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() {
// 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);
}
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)
setOperand(i, To); // Fix it now...
}
}
+