[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp

Vikram Adve vadve at cs.uiuc.edu
Tue Jun 3 21:11:01 PDT 2003


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.33 -> 1.34

---
Log message:

Undo one of those last fixes -- it was incorrect.


---
Diffs of the changes:

Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.33 llvm/lib/Target/TargetData.cpp:1.34
--- llvm/lib/Target/TargetData.cpp:1.33	Mon Jun  2 00:21:06 2003
+++ llvm/lib/Target/TargetData.cpp	Tue Jun  3 21:10:37 2003
@@ -193,10 +193,12 @@
       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");





More information about the llvm-commits mailing list