aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2010-02-11 17:44:04 +0000
committerEric Christopher <echristo@apple.com>2010-02-11 17:44:04 +0000
commitdfdddd8ed621a44ec3da0e2fff42abf9e60e812a (patch)
tree9a5d3227f547edf61ce79d034116d7c5b196a4f3 /lib
parentba6e033f4f2b22dce4766a55dead8385a955fd46 (diff)
downloadexternal_llvm-dfdddd8ed621a44ec3da0e2fff42abf9e60e812a.zip
external_llvm-dfdddd8ed621a44ec3da0e2fff42abf9e60e812a.tar.gz
external_llvm-dfdddd8ed621a44ec3da0e2fff42abf9e60e812a.tar.bz2
Make sure that ConstantExpr offsets also aren't off of extern
symbols. Thanks to Duncan Sands for the testcase! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95877 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/InstCombine/InstCombineCalls.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 1371fa7..43419eb 100644
--- a/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -331,9 +331,15 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
if (CE->getOpcode() != Instruction::GetElementPtr) break;
GEPOperator *GEP = cast<GEPOperator>(CE);
+ // Make sure we're not a constant offset from an external
+ // global.
+ Value *Operand = GEP->getPointerOperand();
+ if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand))
+ if (!GV->hasDefinitiveInitializer()) break;
+
// Get what we're pointing to and its size.
const PointerType *PT =
- cast<PointerType>(GEP->getPointerOperand()->getType());
+ cast<PointerType>(Operand->getType());
size_t Size = TD->getTypeAllocSize(PT->getElementType());
// Get the current byte offset into the thing.
@@ -345,7 +351,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
Constant *RetVal = ConstantInt::get(ReturnTy, Size-Offset);
return ReplaceInstUsesWith(CI, RetVal);
- }
+ }
}
case Intrinsic::bswap:
// bswap(bswap(x)) -> x