summaryrefslogtreecommitdiff
path: root/lib/Target/TargetData.cpp
diff options
context:
space:
mode:
authorVikram S. Adve <vadve@cs.uiuc.edu>2002-08-24 14:44:58 +0000
committerVikram S. Adve <vadve@cs.uiuc.edu>2002-08-24 14:44:58 +0000
commitf519b999a62996b91923d5aa3d71fba86291b4f3 (patch)
treea2c1535592559a2f1a947667268234ae4d03a280 /lib/Target/TargetData.cpp
parent42eb2bae8ee4bf94a50a804149f042f11702c36c (diff)
downloadllvm-f519b999a62996b91923d5aa3d71fba86291b4f3.tar.gz
llvm-f519b999a62996b91923d5aa3d71fba86291b4f3.tar.bz2
llvm-f519b999a62996b91923d5aa3d71fba86291b4f3.tar.xz
Fix sign-extension: it needs to happen *after* multiplying by type size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3497 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetData.cpp')
-rw-r--r--lib/Target/TargetData.cpp6
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp
index 6786af3982..7c55f6730e 100644
--- a/lib/Target/TargetData.cpp
+++ b/lib/Target/TargetData.cpp
@@ -164,12 +164,10 @@ 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.
- // Also, the arrayIdx needs to be sign-extended from 32 bits to uint64_t
- // since uint is not normally sign-extended when cast to uint64_t.
+ // Also, the product needs to be sign-extended from 32 to 64 bits.
uint64_t elementSize = this->getTypeSize(Ty);
uint64_t arrayIdx = cast<ConstantUInt>(Idx[CurIDX])->getValue();
- arrayIdx = (uint64_t) (int) arrayIdx; // sign-extend from 32 to 64 bits
- Result += arrayIdx * elementSize;
+ Result += (uint64_t) (int) (arrayIdx * elementSize); // sign-extend
} else if (const StructType *STy = dyn_cast<const StructType>(Ty)) {
assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx");