From 67d0498d533eedab90e5b6399669c420abbde7c6 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 28 Jul 2010 17:11:36 +0000 Subject: [PATCH] Do GEP offset calculations with unsigned math rather than signed math to avoid undefined behavior on overflow, noticed by John Regehr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109594 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/TargetData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 9b207c1f28c..65f514c2647 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -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(Indices[CurIDX])->getSExtValue()) - Result += arrayIdx * (int64_t)getTypeAllocSize(Ty); + Result += (uint64_t)arrayIdx * getTypeAllocSize(Ty); } }