diff options
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 14 | ||||
-rw-r--r-- | lib/VMCore/Globals.cpp | 21 | ||||
-rw-r--r-- | lib/VMCore/Module.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 4 |
4 files changed, 30 insertions, 12 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 8834e1e2a2..656a7bed74 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -926,7 +926,7 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) { assert(0 && "Invalid alias linkage"); } - const GlobalValue *Aliasee = GA->getAliasee(); + const Constant *Aliasee = dyn_cast_or_null<Constant>(GA->getAliasee()); assert(Aliasee && "Aliasee cannot be null"); if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Aliasee)) { @@ -940,9 +940,15 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) { Out << getLLVMName(F->getName(), GlobalPrefix); else Out << "@\"\""; - } else - assert(0 && "Unsupported aliasee"); - + } else { + const ConstantExpr *CE = 0; + if ((CE = dyn_cast<ConstantExpr>(Aliasee)) && + (CE->getOpcode() == Instruction::BitCast)) { + writeOperand(CE, false); + } else + assert(0 && "Unsupported aliasee"); + } + printInfoComment(*GA); Out << "\n"; } diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp index c64b719095..88a8c0b2a7 100644 --- a/lib/VMCore/Globals.cpp +++ b/lib/VMCore/Globals.cpp @@ -163,12 +163,15 @@ void GlobalVariable::replaceUsesOfWithOnConstant(Value *From, Value *To, //===----------------------------------------------------------------------===// GlobalAlias::GlobalAlias(const Type *Ty, LinkageTypes Link, - const std::string &Name, const GlobalValue* aliasee, + const std::string &Name, Constant* aliasee, Module *ParentModule) - : GlobalValue(Ty, Value::GlobalAliasVal, 0, 0, - Link, Name), Aliasee(aliasee) { + : GlobalValue(Ty, Value::GlobalAliasVal, &Aliasee, 1, Link, Name) { LeakDetector::addGarbageObject(this); + if (aliasee) + assert(aliasee->getType() == Ty && "Alias and aliasee types should match!"); + Aliasee.init(aliasee, this); + if (ParentModule) ParentModule->getAliasList().push_back(this); } @@ -190,12 +193,16 @@ void GlobalAlias::eraseFromParent() { } bool GlobalAlias::isDeclaration() const { - return (Aliasee && Aliasee->isDeclaration()); + const GlobalValue* AV = dyn_cast_or_null<const GlobalValue>(getAliasee()); + return (AV && AV->isDeclaration()); } -void GlobalAlias::setAliasee(const GlobalValue *GV) +void GlobalAlias::setAliasee(Constant *Aliasee) { - // FIXME: Some checks? - Aliasee = GV; + if (Aliasee) { + assert(Aliasee->getType() == getType() && + "Alias and aliasee types should match!"); + setOperand(0, Aliasee); + } } diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index c66032388b..e20dab30be 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -298,6 +298,9 @@ void Module::dropAllReferences() { for(Module::global_iterator I = global_begin(), E = global_end(); I != E; ++I) I->dropAllReferences(); + + for(Module::alias_iterator I = alias_begin(), E = alias_end(); I != E; ++I) + I->dropAllReferences(); } void Module::addLibrary(const std::string& Lib) { diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 1578c2ddd6..01eb860f91 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -316,7 +316,9 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) { Assert1(GA.hasExternalLinkage() || GA.hasInternalLinkage() || GA.hasWeakLinkage(), "Alias should have external or external weak linkage!", &GA); - + Assert1(GA.getType() == GA.getAliasee()->getType(), + "Alias and aliasee types should match!", &GA); + visitGlobalValue(GA); } |