diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-07-13 03:42:38 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-07-13 03:42:38 +0000 |
commit | 17c5ce914ce1bb9b8583a57c4fd566224104ecc0 (patch) | |
tree | 8d94f33d671f2e2969c5160185e775b074a1a255 /lib/IR/DataLayout.cpp | |
parent | 43ac9a4a1eda23eaf81995b6abdb2b157c86ffe5 (diff) |
[IR] Make getIndexedOffsetInType return a signed result
A GEPed offset can go negative, the result of getIndexedOffsetInType
should according be a signed type.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275246 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/DataLayout.cpp')
-rw-r--r-- | lib/IR/DataLayout.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index dc4b8981be7..20a15fb8831 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -723,9 +723,9 @@ unsigned DataLayout::getLargestLegalIntTypeSizeInBits() const { return Max != LegalIntWidths.end() ? *Max : 0; } -uint64_t DataLayout::getIndexedOffsetInType(Type *ElemTy, - ArrayRef<Value *> Indices) const { - uint64_t Result = 0; +int64_t DataLayout::getIndexedOffsetInType(Type *ElemTy, + ArrayRef<Value *> Indices) const { + int64_t Result = 0; // We can use 0 as the address space as we don't need // to get pointer types back from gep_type_iterator. @@ -735,7 +735,7 @@ uint64_t DataLayout::getIndexedOffsetInType(Type *ElemTy, GTE = gep_type_end(ElemTy, AS, Indices); for (; GTI != GTE; ++GTI) { Value *Idx = GTI.getOperand(); - if (StructType *STy = dyn_cast<StructType>(*GTI)) { + if (auto *STy = dyn_cast<StructType>(*GTI)) { assert(Idx->getType()->isIntegerTy(32) && "Illegal struct idx"); unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue(); @@ -747,7 +747,7 @@ uint64_t DataLayout::getIndexedOffsetInType(Type *ElemTy, } else { // Get the array index and the size of each array element. if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue()) - Result += (uint64_t)arrayIdx * getTypeAllocSize(GTI.getIndexedType()); + Result += arrayIdx * getTypeAllocSize(GTI.getIndexedType()); } } |