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

Chris Lattner lattner at cs.uiuc.edu
Thu Jul 1 12:34:01 PDT 2004


Changes in directory llvm/lib/Target:

TargetData.cpp updated: 1.46 -> 1.47

---
Log message:

Handle targets where alignment can be bigger than the size of the data.
Contributed by Vladimir Prus!


---
Diffs of the changes:  (+4 -4)

Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.46 llvm/lib/Target/TargetData.cpp:1.47
--- llvm/lib/Target/TargetData.cpp:1.46	Thu Jun 17 13:19:28 2004
+++ llvm/lib/Target/TargetData.cpp	Thu Jul  1 12:32:59 2004
@@ -168,19 +168,19 @@
     Size = TD->getPointerSize(); Alignment = TD->getPointerAlignment();
     return;
   case Type::ArrayTyID: {
-    const ArrayType *ATy = (const ArrayType *)Ty;
+    const ArrayType *ATy = cast<ArrayType>(Ty);
+    unsigned AlignedSize = (Size + Alignment - 1)/Alignment*Alignment;
     getTypeInfo(ATy->getElementType(), TD, Size, Alignment);
-    Size *= ATy->getNumElements();
+    Size = AlignedSize*ATy->getNumElements();
     return;
   }
   case Type::StructTyID: {
     // Get the layout annotation... which is lazily created on demand.
-    const StructLayout *Layout = TD->getStructLayout((const StructType*)Ty);
+    const StructLayout *Layout = TD->getStructLayout(cast<StructType>(Ty));
     Size = Layout->StructSize; Alignment = Layout->StructAlignment;
     return;
   }
     
-  case Type::TypeTyID:
   default:
     assert(0 && "Bad type for getTypeInfo!!!");
     return;





More information about the llvm-commits mailing list