* Fix divide by zero error with empty structs
authorChris Lattner <sabre@nondot.org>
Wed, 21 May 2003 18:08:44 +0000 (18:08 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 21 May 2003 18:08:44 +0000 (18:08 +0000)
* Empty structs should have ALIGNMENT 1, not SIZE 1.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6263 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/TargetData.cpp

index 158f57e3accf2941e27022c9c5d7ada39d0eb432..1c6f9d1aa31b69783f2eaea8d0fe4d11c48507fc 100644 (file)
@@ -56,15 +56,13 @@ StructLayout::StructLayout(const StructType *ST, const TargetData &TD)
     StructSize += TySize;                 // Consume space for this data item
   }
 
+  // Empty structures have alignment of 1 byte.
+  if (StructAlignment == 0) StructAlignment = 1;
+
   // Add padding to the end of the struct so that it could be put in an array
   // and all array elements would be aligned correctly.
   if (StructSize % StructAlignment != 0)
     StructSize = (StructSize/StructAlignment + 1) * StructAlignment;
-
-  if (StructSize == 0) {
-    StructSize = 1;           // Empty struct is 1 byte
-    StructAlignment = 1;
-  }
 }
 
 Annotation *TargetData::TypeAnFactory(AnnotationID AID, const Annotable *T,