diff options
author | Chris Lattner <sabre@nondot.org> | 2007-05-15 00:16:00 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-05-15 00:16:00 +0000 |
commit | 234f96daa8a44e8f0cb19a0b726143ef8804da1f (patch) | |
tree | 211362a7326d9d3f765d052223d8521270e81bd2 /llvm | |
parent | 120548e5087b6d5755af965f63ecfa63230521f1 (diff) | |
download | bcm5719-llvm-234f96daa8a44e8f0cb19a0b726143ef8804da1f.tar.gz bcm5719-llvm-234f96daa8a44e8f0cb19a0b726143ef8804da1f.zip |
Fix Transforms/InstCombine/2007-05-14-Crash.ll
llvm-svn: 37057
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 01385db6c14..08905576d22 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -6454,16 +6454,25 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) { while (Offset) { if (const StructType *STy = dyn_cast<StructType>(GEPIdxTy)) { const StructLayout *SL = TD->getStructLayout(STy); - unsigned Elt = SL->getElementContainingOffset(Offset); - NewIndices.push_back(ConstantInt::get(Type::Int32Ty, Elt)); + if (Offset < (int64_t)SL->getSizeInBytes()) { + unsigned Elt = SL->getElementContainingOffset(Offset); + NewIndices.push_back(ConstantInt::get(Type::Int32Ty, Elt)); - Offset -= SL->getElementOffset(Elt); - GEPIdxTy = STy->getElementType(Elt); + Offset -= SL->getElementOffset(Elt); + GEPIdxTy = STy->getElementType(Elt); + } else { + // Otherwise, we can't index into this, bail out. + Offset = 0; + OrigBase = 0; + } } else if (isa<ArrayType>(GEPIdxTy) || isa<VectorType>(GEPIdxTy)) { const SequentialType *STy = cast<SequentialType>(GEPIdxTy); - uint64_t EltSize = TD->getTypeSize(STy->getElementType()); - NewIndices.push_back(ConstantInt::get(IntPtrTy, Offset/EltSize)); - Offset %= EltSize; + if (uint64_t EltSize = TD->getTypeSize(STy->getElementType())) { + NewIndices.push_back(ConstantInt::get(IntPtrTy,Offset/EltSize)); + Offset %= EltSize; + } else { + NewIndices.push_back(ConstantInt::get(IntPtrTy, 0)); + } GEPIdxTy = STy->getElementType(); } else { // Otherwise, we can't index into this, bail out. |