diff options
author | Vikram S. Adve <vadve@cs.uiuc.edu> | 2002-08-23 02:55:51 +0000 |
---|---|---|
committer | Vikram S. Adve <vadve@cs.uiuc.edu> | 2002-08-23 02:55:51 +0000 |
commit | 69f3b7259408e066a33edf3f2904f4454b210367 (patch) | |
tree | 11d1436dadcab248c27479b7567972c73b88290a /lib/Target/TargetData.cpp | |
parent | 3bb8ad27a81661865400fcff5e07d0461860faf7 (diff) |
Force sign-extension for uint array indexes from 32-bit to 64-bits
since uint is not normally sign-extended when casting to uint64_t.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3489 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetData.cpp')
-rw-r--r-- | lib/Target/TargetData.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 54acd08966..48fca1ebdf 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -164,8 +164,13 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy, // Get the array index and the size of each array element. // Both must be known constants, or this will fail. - unsigned arrayIdx = cast<ConstantUInt>(Idx[CurIDX])->getValue(); + // Also, the arrayIdx needs to be sign-extended from uint + // to the machine register size if the reg. size > sizeof(uint). uint64_t elementSize = this->getTypeSize(Ty); + uint64_t arrayIdx = cast<ConstantUInt>(Idx[CurIDX])->getValue(); + if (getIntegerRegize() > sizeof(uint)) { + arrayIdx = (uint64_t) (int) arrayIdx; // sign-extend from 32 to 64 bits + } Result += arrayIdx * elementSize; } else if (const StructType *STy = dyn_cast<const StructType>(Ty)) { |