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 | 17bdf445e42e902dbd97e80facfdeaa7cb6e61f8 (patch) | |
tree | a457a53855e37c37f7e47eeab7d42548bac19d40 /llvm/lib/IR/DataLayout.cpp | |
parent | f12c28d0089383cb21bef94015b7e65faa5919f2 (diff) | |
download | bcm5719-llvm-17bdf445e42e902dbd97e80facfdeaa7cb6e61f8.tar.gz bcm5719-llvm-17bdf445e42e902dbd97e80facfdeaa7cb6e61f8.zip |
[IR] Make getIndexedOffsetInType return a signed result
A GEPed offset can go negative, the result of getIndexedOffsetInType
should according be a signed type.
llvm-svn: 275246
Diffstat (limited to 'llvm/lib/IR/DataLayout.cpp')
-rw-r--r-- | llvm/lib/IR/DataLayout.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index dc4b8981be7..20a15fb8831 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/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()); } } |