diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-26 06:14:40 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-26 06:14:40 +0000 |
commit | 72db10a9959431a710712f64d4b98299ab5a022d (patch) | |
tree | 8ea039520d3cec3f1adcf367c2a6915744f6a559 /lib/IR | |
parent | 360ee971798ebccc177f7e1c2947a74e3bd9fbc0 (diff) | |
download | llvm-72db10a9959431a710712f64d4b98299ab5a022d.tar.gz llvm-72db10a9959431a710712f64d4b98299ab5a022d.tar.bz2 llvm-72db10a9959431a710712f64d4b98299ab5a022d.tar.xz |
Revert "Prevent alias from pointing to weak aliases."
This reverts commit r204781.
I will follow up to with msan folks to see what is what they
were trying to do with aliases to weak aliases.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204784 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r-- | lib/IR/Globals.cpp | 35 | ||||
-rw-r--r-- | lib/IR/Verifier.cpp | 10 |
2 files changed, 24 insertions, 21 deletions
diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index f338dd76aa..11152d5d6c 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -236,10 +236,10 @@ void GlobalAlias::setAliasee(Constant *Aliasee) { setOperand(0, Aliasee); } -static GlobalValue *getAliaseeGV(GlobalAlias *GA) { - Constant *C = GA->getAliasee(); - assert(C && "Must alias something"); - +GlobalValue *GlobalAlias::getAliasedGlobal() { + Constant *C = getAliasee(); + if (C == 0) return 0; + if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) return GV; @@ -248,23 +248,30 @@ static GlobalValue *getAliaseeGV(GlobalAlias *GA) { CE->getOpcode() == Instruction::AddrSpaceCast || CE->getOpcode() == Instruction::GetElementPtr) && "Unsupported aliasee"); - + return cast<GlobalValue>(CE->getOperand(0)); } -GlobalValue *GlobalAlias::getAliasedGlobal() { +GlobalValue *GlobalAlias::resolveAliasedGlobal(bool stopOnWeak) { SmallPtrSet<GlobalValue*, 3> Visited; - GlobalAlias *GA = this; + // Check if we need to stop early. + if (stopOnWeak && mayBeOverridden()) + return this; + + GlobalValue *GV = getAliasedGlobal(); + Visited.insert(GV); + + // Iterate over aliasing chain, stopping on weak alias if necessary. + while (GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) { + if (stopOnWeak && GA->mayBeOverridden()) + break; + + GV = GA->getAliasedGlobal(); - for (;;) { - GlobalValue *GV = getAliaseeGV(GA); if (!Visited.insert(GV)) return 0; - - // Iterate over aliasing chain. - GA = dyn_cast<GlobalAlias>(GV); - if (!GA) - return GV; } + + return GV; } diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index f5c8ac623b..50c6ae204e 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -502,14 +502,10 @@ void Verifier::visitGlobalAlias(const GlobalAlias &GA) { } } Assert1(!GV->isDeclaration(), "Alias must point to a definition", &GA); - if (const GlobalAlias *GAAliasee = dyn_cast<GlobalAlias>(GV)) { - Assert1(!GAAliasee->mayBeOverridden(), "Alias cannot point to a weak alias", - &GA); - } - const GlobalValue *AG = GA.getAliasedGlobal(); - Assert1(AG, "Aliasing chain should end with function or global variable", - &GA); + const GlobalValue* Resolved = GA.resolveAliasedGlobal(/*stopOnWeak*/ false); + Assert1(Resolved, + "Aliasing chain should end with function or global variable", &GA); visitGlobalValue(GA); } |