aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-06-04 07:01:56 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-06-04 07:01:56 +0000
commit38eb9f46db418ff8a75ef95841097a2ab6ebbc41 (patch)
tree3363028f84c80e039739eac29f382cdc83bd23d0 /llvm/lib/IR/ConstantFold.cpp
parent214335d703197bdb2f7f06bcce8c31fe2112b94e (diff)
downloadllvm-38eb9f46db418ff8a75ef95841097a2ab6ebbc41.zip
llvm-38eb9f46db418ff8a75ef95841097a2ab6ebbc41.tar.gz
llvm-38eb9f46db418ff8a75ef95841097a2ab6ebbc41.tar.bz2
[ConstantFold] Don't skip the first gep index when folding geps
We neglected to check if the first index made the GEP ineligible for 'inbounds'. This fixes PR23753. llvm-svn: 239015
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 3f64c43..2efc6124 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -2165,9 +2165,9 @@ static Constant *ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C,
// factored out into preceding dimensions.
bool Unknown = false;
SmallVector<Constant *, 8> NewIdxs;
- Type *Ty = PointeeTy;
- Type *Prev = C->getType();
- for (unsigned i = 1, e = Idxs.size(); i != e;
+ Type *Ty = C->getType();
+ Type *Prev = nullptr;
+ for (unsigned i = 0, e = Idxs.size(); i != e;
Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[i]), ++i) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Idxs[i])) {
if (isa<ArrayType>(Ty) || isa<VectorType>(Ty))