diff options
author | Vikram S. Adve <vadve@cs.uiuc.edu> | 2003-06-04 02:10:37 +0000 |
---|---|---|
committer | Vikram S. Adve <vadve@cs.uiuc.edu> | 2003-06-04 02:10:37 +0000 |
commit | 55a85a47d4cb7bed22cd03f9f8003441a33cf1a7 (patch) | |
tree | e593cfa674566d9b07f0ae8034ea248b590b22af | |
parent | 88fe358f8aaf611f72eb1b79acb72d94e345ecb0 (diff) | |
download | external_llvm-55a85a47d4cb7bed22cd03f9f8003441a33cf1a7.zip external_llvm-55a85a47d4cb7bed22cd03f9f8003441a33cf1a7.tar.gz external_llvm-55a85a47d4cb7bed22cd03f9f8003441a33cf1a7.tar.bz2 |
Undo one of those last fixes -- it was incorrect.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6593 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Target/TargetData.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index ede96f7..bdeb4e9 100644 --- a/lib/Target/TargetData.cpp +++ b/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"); |