Fix a bug where we would evaluate stores into linkonce objects which could be

potentially replaced at link-time.

llvm-svn: 23463
This commit is contained in:
Chris Lattner 2005-09-27 04:50:03 +00:00
parent dc94923d86
commit b3b15ed0a3

View 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);
}