summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorVikram S. Adve <vadve@cs.uiuc.edu>2003-06-04 02:10:37 +0000
committerVikram S. Adve <vadve@cs.uiuc.edu>2003-06-04 02:10:37 +0000
commit680ee9f63481b696544a27b1c92e44d182a90a75 (patch)
treee7c9b0b292bd990194e8d6e94e1287b0f02c2c0c /llvm/lib
parent905496e94f9892f0d48f682490ecd511737aa293 (diff)
downloadbcm5719-llvm-680ee9f63481b696544a27b1c92e44d182a90a75.tar.gz
bcm5719-llvm-680ee9f63481b696544a27b1c92e44d182a90a75.zip
Undo one of those last fixes -- it was incorrect.
llvm-svn: 6593
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/TargetData.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Target/TargetData.cpp b/llvm/lib/Target/TargetData.cpp
index ede96f7aaed..bdeb4e99c6a 100644
--- a/llvm/lib/Target/TargetData.cpp
+++ b/llvm/lib/Target/TargetData.cpp
@@ -193,10 +193,12 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy,
Ty = cast<SequentialType>(Ty)->getElementType();
// Get the array index and the size of each array element.
- // Both must be known constants, or the index shd be 0; else this fails.
+ // The size must be a known value, except if arrayIdx is 0.
+ // In particular, don't try to get the type size if the arrayIdx is 0:
+ // 0 index into an unsized type is legal and should be allowed.
int64_t arrayIdx = cast<ConstantSInt>(Idx[CurIDX])->getValue();
- Result += arrayIdx * (int64_t)getTypeSize(Ty);
-
+ Result += arrayIdx == 0? 0
+ : arrayIdx * (int64_t)getTypeSize(Ty);
} else {
const StructType *STy = cast<StructType>(Ty);
assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx");
OpenPOWER on IntegriCloud