When the number of elements is zero, don't malloc 32GB on 64-bit systems.
authorJeff Cohen <jeffc@jolt-lang.org>
Mon, 9 Apr 2007 19:26:30 +0000 (19:26 +0000)
committerJeff Cohen <jeffc@jolt-lang.org>
Mon, 9 Apr 2007 19:26:30 +0000 (19:26 +0000)
Fixes unexpected failures on FreeBSD/amd64 of:
  CFrontend/2005-09-24-BitFieldCrash.c:
  CFrontend/2007-02-04-EmptyStruct.c:
  CFrontend/2007-03-26-ZeroWidthBitfield.c:
  CodeGen/Generic/2005-10-18-ZeroSizeStackObject.ll:

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

lib/Target/TargetData.cpp

index b1f08079f0e84e577bf68254dfe62e6eb2287c2c..10ee707aea4df205779d6348f9da880ff623e57b 100644 (file)
@@ -342,7 +342,7 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
 
   // Otherwise, create the struct layout.  Because it is variable length, we 
   // malloc it, then use placement new.
-  unsigned NumElts = Ty->getNumElements();
+  int NumElts = Ty->getNumElements();
   StructLayout *L =
     (StructLayout *)malloc(sizeof(StructLayout)+(NumElts-1)*sizeof(uint64_t));