[llvm-commits] [PATCH] Fix type size calculation in CreateMalloc(), getMallocArraySize(), and isArrayMalloc()
Victor Hernandez
vhernandez at apple.com
Fri Sep 11 11:14:01 PDT 2009
Duncan,
You are right. My mistake also got caught by test/CodeGen/X86/x86-64-
malloc.ll when MallocInst is avoided (not the default mode).
Instead of switching away from ConstantExpr::getSizeOf, I fixed
isArrayMalloc() to cast ElementSize to the right size.
Here is the new patch:
thanks,
Victor
On Sep 11, 2009, at 10:08 AM, Duncan Sands wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090911/fba3cb8e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FixTypeSize2.diff
Type: application/octet-stream
Size: 5394 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090911/fba3cb8e/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090911/fba3cb8e/attachment-0001.html>
More information about the llvm-commits
mailing list