[llvm-commits] CVS: llvm/lib/Transforms/IPO/GlobalOpt.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Sep 26 21:50:15 PDT 2005



Changes in directory llvm/lib/Transforms/IPO:

GlobalOpt.cpp updated: 1.55 -> 1.56
---
Log message:

Fix a bug where we would evaluate stores into linkonce objects which could be
potentially replaced at link-time.


---
Diffs of the changes:  (+6 -1)

 GlobalOpt.cpp |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp
diff -u llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.55 llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.56
--- llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.55	Mon Sep 26 23:45:34 2005
+++ llvm/lib/Transforms/IPO/GlobalOpt.cpp	Mon Sep 26 23:50:03 2005
@@ -1239,13 +1239,18 @@
 /// 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);
     }






More information about the llvm-commits mailing list