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 | |
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')
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JITEmitter.cpp | 2 | ||||
-rw-r--r-- | lib/IR/Globals.cpp | 35 | ||||
-rw-r--r-- | lib/IR/Verifier.cpp | 10 | ||||
-rw-r--r-- | lib/Target/PowerPC/PPCAsmPrinter.cpp | 12 | ||||
-rw-r--r-- | lib/Target/PowerPC/PPCFastISel.cpp | 2 | ||||
-rw-r--r-- | lib/Target/PowerPC/PPCISelDAGToDAG.cpp | 4 | ||||
-rw-r--r-- | lib/Target/TargetMachine.cpp | 2 | ||||
-rw-r--r-- | lib/Target/X86/X86FastISel.cpp | 2 | ||||
-rw-r--r-- | lib/Target/X86/X86ISelLowering.cpp | 2 | ||||
-rw-r--r-- | lib/Target/XCore/XCoreISelLowering.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/Instrumentation/DataFlowSanitizer.cpp | 3 |
12 files changed, 41 insertions, 37 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 52806235fd..61961d8ca2 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -1172,7 +1172,7 @@ SDValue SelectionDAG::getGlobalAddress(const GlobalValue *GV, SDLoc DL, if (!GVar) { // If GV is an alias then use the aliasee for determining thread-localness. if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) - GVar = dyn_cast_or_null<GlobalVariable>(GA->getAliasedGlobal()); + GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal(false)); } unsigned Opc; diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index 9d215ec96a..4b2f012eaf 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -688,7 +688,7 @@ void *JITEmitter::getPointerToGlobal(GlobalValue *V, void *Reference, return TheJIT->getOrEmitGlobalVariable(GV); if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) - return TheJIT->getPointerToGlobal(GA->getAliasedGlobal()); + return TheJIT->getPointerToGlobal(GA->resolveAliasedGlobal(false)); // If we have already compiled the function, return a pointer to its body. Function *F = cast<Function>(V); 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); } diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp index 9ce8ea911c..daf90c86ef 100644 --- a/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -381,8 +381,8 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) { if (MO.isGlobal()) { const GlobalValue *GValue = MO.getGlobal(); const GlobalAlias *GAlias = dyn_cast<GlobalAlias>(GValue); - const GlobalValue *RealGValue = - GAlias ? GAlias->getAliasedGlobal() : GValue; + const GlobalValue *RealGValue = GAlias ? + GAlias->resolveAliasedGlobal(false) : GValue; MOSymbol = getSymbol(RealGValue); const GlobalVariable *GVar = dyn_cast<GlobalVariable>(RealGValue); IsExternal = GVar && !GVar->hasInitializer(); @@ -428,8 +428,8 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) { else if (MO.isGlobal()) { const GlobalValue *GValue = MO.getGlobal(); const GlobalAlias *GAlias = dyn_cast<GlobalAlias>(GValue); - const GlobalValue *RealGValue = - GAlias ? GAlias->getAliasedGlobal() : GValue; + const GlobalValue *RealGValue = GAlias ? + GAlias->resolveAliasedGlobal(false) : GValue; MOSymbol = getSymbol(RealGValue); const GlobalVariable *GVar = dyn_cast<GlobalVariable>(RealGValue); @@ -463,8 +463,8 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) { if (MO.isGlobal()) { const GlobalValue *GValue = MO.getGlobal(); const GlobalAlias *GAlias = dyn_cast<GlobalAlias>(GValue); - const GlobalValue *RealGValue = - GAlias ? GAlias->getAliasedGlobal() : GValue; + const GlobalValue *RealGValue = GAlias ? + GAlias->resolveAliasedGlobal(false) : GValue; MOSymbol = getSymbol(RealGValue); const GlobalVariable *GVar = dyn_cast<GlobalVariable>(RealGValue); IsExternal = GVar && !GVar->hasInitializer(); diff --git a/lib/Target/PowerPC/PPCFastISel.cpp b/lib/Target/PowerPC/PPCFastISel.cpp index dd45683032..4753160e09 100644 --- a/lib/Target/PowerPC/PPCFastISel.cpp +++ b/lib/Target/PowerPC/PPCFastISel.cpp @@ -1863,7 +1863,7 @@ unsigned PPCFastISel::PPCMaterializeGV(const GlobalValue *GV, MVT VT) { if (!GVar) { // If GV is an alias, use the aliasee for determining thread-locality. if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) - GVar = dyn_cast_or_null<GlobalVariable>(GA->getAliasedGlobal()); + GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal(false)); } // FIXME: We don't yet handle the complexity of TLS. diff --git a/lib/Target/PowerPC/PPCISelDAGToDAG.cpp b/lib/Target/PowerPC/PPCISelDAGToDAG.cpp index 0e75bb4575..5b09588e0f 100644 --- a/lib/Target/PowerPC/PPCISelDAGToDAG.cpp +++ b/lib/Target/PowerPC/PPCISelDAGToDAG.cpp @@ -1413,8 +1413,8 @@ SDNode *PPCDAGToDAGISel::Select(SDNode *N) { if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(GA)) { const GlobalValue *GValue = G->getGlobal(); const GlobalAlias *GAlias = dyn_cast<GlobalAlias>(GValue); - const GlobalValue *RealGValue = - GAlias ? GAlias->getAliasedGlobal() : GValue; + const GlobalValue *RealGValue = GAlias ? + GAlias->resolveAliasedGlobal(false) : GValue; const GlobalVariable *GVar = dyn_cast<GlobalVariable>(RealGValue); assert((GVar || isa<Function>(RealGValue)) && "Unexpected global value subclass!"); diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp index fe3c870c98..f8a58ec292 100644 --- a/lib/Target/TargetMachine.cpp +++ b/lib/Target/TargetMachine.cpp @@ -129,7 +129,7 @@ TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const { // If GV is an alias then use the aliasee for determining // thread-localness. if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) - GV = GA->getAliasedGlobal(); + GV = GA->resolveAliasedGlobal(false); const GlobalVariable *Var = cast<GlobalVariable>(GV); bool isLocal = Var->hasLocalLinkage(); diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index 9c57f0d1f1..c3e002082d 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -363,7 +363,7 @@ bool X86FastISel::handleConstantAddresses(const Value *V, X86AddressMode &AM) { // it works...). if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) if (const GlobalVariable *GVar = - dyn_cast_or_null<GlobalVariable>(GA->getAliasedGlobal())) + dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal(false))) if (GVar->isThreadLocal()) return false; diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 630fba0151..ec923ba7aa 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -8509,7 +8509,7 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { // If GV is an alias then use the aliasee for determining // thread-localness. if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) - GV = GA->getAliasedGlobal(); + GV = GA->resolveAliasedGlobal(false); SDLoc dl(GA); SDValue Chain = DAG.getEntryNode(); diff --git a/lib/Target/XCore/XCoreISelLowering.cpp b/lib/Target/XCore/XCoreISelLowering.cpp index 1b74013ac1..079e886457 100644 --- a/lib/Target/XCore/XCoreISelLowering.cpp +++ b/lib/Target/XCore/XCoreISelLowering.cpp @@ -277,7 +277,7 @@ getGlobalAddressWrapper(SDValue GA, const GlobalValue *GV, const GlobalValue *UnderlyingGV = GV; // If GV is an alias then use the aliasee to determine the wrapper type if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) - UnderlyingGV = GA->getAliasedGlobal(); + UnderlyingGV = GA->resolveAliasedGlobal(); if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(UnderlyingGV)) { if ( ( GVar->isConstant() && UnderlyingGV->isLocalLinkage(GV->getLinkage()) ) diff --git a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp index df1549d405..0249df1c6d 100644 --- a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -554,7 +554,8 @@ bool DataFlowSanitizer::runOnModule(Module &M) { ++i; // Don't stop on weak. We assume people aren't playing games with the // instrumentedness of overridden weak aliases. - if (Function *F = dyn_cast<Function>(GA->getAliasedGlobal())) { + if (Function *F = dyn_cast<Function>( + GA->resolveAliasedGlobal(/*stopOnWeak=*/false))) { bool GAInst = isInstrumented(GA), FInst = isInstrumented(F); if (GAInst && FInst) { addGlobalNamePrefix(GA); |