From 231308c54538c1f50d7175f76b26e3d368e4703e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 27 Sep 2005 04:50:03 +0000 Subject: [PATCH] Fix a bug where we would evaluate stores into linkonce objects which could be potentially replaced at link-time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23463 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/GlobalOpt.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 6170bfcac64..a3cd8d4f15d 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -1239,13 +1239,18 @@ static Constant *getVal(std::map &ComputedValues, /// we punt. We basically just support direct accesses to globals and GEP's of /// globals. This should be kept up to date with CommitValueTo. static bool isSimpleEnoughPointerToCommit(Constant *C) { - if (GlobalVariable *GV = dyn_cast(C)) + if (GlobalVariable *GV = dyn_cast(C)) { + if (!GV->hasExternalLinkage() && !GV->hasInternalLinkage()) + return false; // do not allow weak/linkonce linkage. return !GV->isExternal(); // reject external globals. + } if (ConstantExpr *CE = dyn_cast(C)) // Handle a constantexpr gep. if (CE->getOpcode() == Instruction::GetElementPtr && isa(CE->getOperand(0))) { GlobalVariable *GV = cast(CE->getOperand(0)); + if (!GV->hasExternalLinkage() && !GV->hasInternalLinkage()) + return false; // do not allow weak/linkonce linkage. return GV->hasInitializer() && ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE); }