diff options
author | Eric Christopher <echristo@apple.com> | 2010-02-11 17:44:04 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2010-02-11 17:44:04 +0000 |
commit | cccdc13662cac1c66bd44003ef6557895e2b23af (patch) | |
tree | 5ab4ae2ef25a90c498e186e8a3cfc9e06da06a3f /llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | |
parent | bcd554f908ad56246754c3924fcc4b377baf321d (diff) | |
download | bcm5719-llvm-cccdc13662cac1c66bd44003ef6557895e2b23af.tar.gz bcm5719-llvm-cccdc13662cac1c66bd44003ef6557895e2b23af.zip |
Make sure that ConstantExpr offsets also aren't off of extern
symbols.
Thanks to Duncan Sands for the testcase!
llvm-svn: 95877
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 1371fa7f1ad..43419eb9fc0 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/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 |