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 | 1c84243d472bdd5ce4028c3266cdf0c3a36bd50b (patch) | |
tree | 2a4bbd7d86ef25fa913cc7e4f51390ec58ff7c4d /llvm/lib/Target/TargetData.cpp | |
parent | 02fe752fbdec8dfe1f2b4968d234402426ddca5e (diff) | |
download | bcm5719-llvm-1c84243d472bdd5ce4028c3266cdf0c3a36bd50b.tar.gz bcm5719-llvm-1c84243d472bdd5ce4028c3266cdf0c3a36bd50b.zip |
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.
llvm-svn: 3489
Diffstat (limited to 'llvm/lib/Target/TargetData.cpp')
-rw-r--r-- | llvm/lib/Target/TargetData.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Target/TargetData.cpp b/llvm/lib/Target/TargetData.cpp index 54acd08966e..48fca1ebdf4 100644 --- a/llvm/lib/Target/TargetData.cpp +++ b/llvm/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)) { |