Do GEP offset calculations with unsigned math rather than signed math

to avoid undefined behavior on overflow, noticed by John Regehr.

llvm-svn: 109594
This commit is contained in:
Dan Gohman 2010-07-28 17:11:36 +00:00
parent 44ee74292f
commit 32f889e552
1 changed files with 1 additions and 1 deletions

View File

@ -625,7 +625,7 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy, Value* const* Indices,
// Get the array index and the size of each array element.
if (int64_t arrayIdx = cast<ConstantInt>(Indices[CurIDX])->getSExtValue())
Result += arrayIdx * (int64_t)getTypeAllocSize(Ty);
Result += (uint64_t)arrayIdx * getTypeAllocSize(Ty);
}
}