diff options
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 5fa56d3..18f481a 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1951,7 +1951,7 @@ static bool isIndexInRangeOfArrayType(uint64_t NumElements, // A negative index or an index past the end of our sequential type is // considered out-of-range. int64_t IndexVal = CI->getSExtValue(); - if (IndexVal < 0 || (NumElements > 0 && (uint64_t)IndexVal >= NumElements)) + if (IndexVal < 0 || (IndexVal != 0 && (uint64_t)IndexVal >= NumElements)) return false; // Otherwise, it is in-range. @@ -2202,11 +2202,17 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C, Unknown = true; continue; } + + // Determine the number of elements in our sequential type. + uint64_t NumElements = STy->getArrayNumElements(); + if (!NumElements) { + Unknown = true; + continue; + } + // It's out of range, but we can factor it into the prior // dimension. NewIdxs.resize(Idxs.size()); - // Determine the number of elements in our sequential type. - uint64_t NumElements = STy->getArrayNumElements(); // Expand the current index or the previous index to a vector from a scalar // if necessary. |