summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target
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
commit9068efdce620f4e00bf4488a4680faedc6520c7c (patch)
treeb67084996944b73fbb402b58863b3d0e325eedf7 /llvm/lib/Target
parentbc27523001e765e6e82719a7ba82b4f74e87e98d (diff)
downloadbcm5719-llvm-9068efdce620f4e00bf4488a4680faedc6520c7c.tar.gz
bcm5719-llvm-9068efdce620f4e00bf4488a4680faedc6520c7c.zip
Fix sign-extension: it needs to happen *after* multiplying by type size.
llvm-svn: 3497
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r--llvm/lib/Target/TargetData.cpp6
1 files changed, 2 insertions, 4 deletions
diff --git a/llvm/lib/Target/TargetData.cpp b/llvm/lib/Target/TargetData.cpp
index 6786af3982d..7c55f6730ed 100644
--- a/llvm/lib/Target/TargetData.cpp
+++ b/llvm/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");
OpenPOWER on IntegriCloud