Fix a bug where we would evaluate stores into linkonce objects which could be
authorChris Lattner <sabre@nondot.org>
Tue, 27 Sep 2005 04:50:03 +0000 (04:50 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 27 Sep 2005 04:50:03 +0000 (04:50 +0000)
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

index 6170bfcac641a144168f5bf148163673ff43cde6..a3cd8d4f15df3c39459bb047010096937747a60c 100644 (file)
@@ -1239,13 +1239,18 @@ static Constant *getVal(std::map<Value*, Constant*> &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<GlobalVariable>(C))
+  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(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<ConstantExpr>(C))
     // Handle a constantexpr gep.
     if (CE->getOpcode() == Instruction::GetElementPtr &&
         isa<GlobalVariable>(CE->getOperand(0))) {
       GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0));
+      if (!GV->hasExternalLinkage() && !GV->hasInternalLinkage())
+        return false;  // do not allow weak/linkonce linkage.
       return GV->hasInitializer() &&
              ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE);
     }