diff options
author | Chris Lattner <sabre@nondot.org> | 2007-05-05 01:59:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-05-05 01:59:31 +0000 |
commit | c42e226f08106834d5743208e38c42861dacae55 (patch) | |
tree | 70bc00bf96a2695cf214f6d74240243a16e74c4b /lib/Transforms | |
parent | 51e04da38191cbc70449742b840ec8207caa9de7 (diff) | |
download | llvm-c42e226f08106834d5743208e38c42861dacae55.tar.gz llvm-c42e226f08106834d5743208e38c42861dacae55.tar.bz2 llvm-c42e226f08106834d5743208e38c42861dacae55.tar.xz |
Fix InstCombine/2007-05-04-Crash.ll and PR1384
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36775 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index b80d4d630a..c30f86e533 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -6404,21 +6404,25 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) { if (GEPIdxTy->isSized()) { SmallVector<Value*, 8> NewIndices; - // Start with the index over the outer type. + // Start with the index over the outer type. Note that the type size + // might be zero (even if the offset isn't zero) if the indexed type + // is something like [0 x {int, int}] const Type *IntPtrTy = TD->getIntPtrType(); - int64_t TySize = TD->getTypeSize(GEPIdxTy); - int64_t FirstIdx = Offset/TySize; - Offset %= TySize; + int64_t FirstIdx = 0; + if (int64_t TySize = TD->getTypeSize(GEPIdxTy)) { + FirstIdx = Offset/TySize; + Offset %= TySize; - // Handle silly modulus not returning values values [0..TySize). - if (Offset < 0) { - --FirstIdx; - Offset += TySize; - assert(Offset >= 0); + // Handle silly modulus not returning values values [0..TySize). + if (Offset < 0) { + --FirstIdx; + Offset += TySize; + assert(Offset >= 0); + } + assert((uint64_t)Offset < (uint64_t)TySize && "Out of range offset"); } NewIndices.push_back(ConstantInt::get(IntPtrTy, FirstIdx)); - assert((uint64_t)Offset < (uint64_t)TySize && "Out of range offset"); // Index into the types. If we fail, set OrigBase to null. while (Offset) { |