diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp index 2369d1c8eaa..cfecbc91ce0 100644 --- a/lib/VMCore/Globals.cpp +++ b/lib/VMCore/Globals.cpp @@ -76,7 +76,11 @@ GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link, const std::string &Name, Module *ParentModule) : GlobalValue(PointerType::get(Ty), Value::GlobalVariableVal, Link, Name), isConstantGlobal(constant) { - if (Initializer) Operands.push_back(Use((Value*)Initializer, this)); + if (Initializer) { + assert(Initializer->getType() == Ty && + "Initializer should be the same type as the GlobalVariable!"); + Operands.push_back(Use((Value*)Initializer, this)); + } LeakDetector::addGarbageObject(this);