Undo one of those last fixes -- it was incorrect.
authorVikram S. Adve <vadve@cs.uiuc.edu>
Wed, 4 Jun 2003 02:10:37 +0000 (02:10 +0000)
committerVikram S. Adve <vadve@cs.uiuc.edu>
Wed, 4 Jun 2003 02:10:37 +0000 (02:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6593 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/TargetData.cpp

index ede96f7aaed9759b76bc26e71a362eee4f749ff8..bdeb4e99c6afc05eb06b685ebd0fc9747f3f2c5b 100644 (file)
@@ -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");