[llvm-commits] [PATCH] Fix type size calculation in CreateMalloc(), getMallocArraySize(), and isArrayMalloc()

Duncan Sands baldrick at free.fr
Fri Sep 11 10:08:21 PDT 2009


Hi Victor,

> Malloc call codegen was using ConstantExpr::getSizeOf() to determine the 
> size of a type, when it should have been using 
> Type-> getPrimitiveSizeInBits().

using ConstantExpr::getSizeOf (which is the same as getTypeAllocSize)
was correct.  Using getPrimitiveSizeInBits is wrong, since it does not
take alignment into account.  Consider x86 long double, which is 80 bits
long (this is what getPrimitiveSizeInBits returns).  If you ask GCC what
sizeof(x86 long double) is, it will tell you 12 bytes or 16 bytes
depending on the platform.  You should be mallocing the same number of
bytes as sizeof gives, 12 or 16, and not 10.

Ciao,

Duncan.


   Fixed that.  isArrayMalloc()now
> correctly identifies array mallocs.
> 
> I also reorganized the InsertBefore vs. InsertAtEnd code 
> in createMalloc() for clarity.
> 
> 
> ------------------------------------------------------------------------
> 
> 
> 
> Victor
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list