[LLVMdev] alloc_size metadata

Duncan Sands baldrick at free.fr
Thu May 24 01:51:39 PDT 2012


Hi Nuno,

> I'm implementing the alloc_size function attribute in clang.

does anyone actually use this attribute?  And if they do, can it really buy
them anything?  How about "implementing" it by ignoring it!

Ciao, Duncan.

  This
> attribute exists in gcc since version 4.3.
> The attribute specifies that a function returns a buffer with the size
> given by the multiplication of the specified arguments.  I would like
> to add new metadata to pass this information to LLVM IR.
>
> For example, take the following C code:
>
> void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2)));
>
> void* fn() {
>     return my_calloc(1, 3);
> }
>
>
> which would get translated to:
>
>
> define i8* @fn() {
> entry:
>     %call = call i8* @my_calloc(i32 1, i32 3), !alloc_size !0
>     ret i8* %call
> }
>
> declare i8* @my_calloc(i32, i32)
>
> !0 = metadata !{i32 0, i32 1}
>
>
> The downsize is that the metadata is added to all call sites, since
> it's not possible to attach metadata to function declarations.
>
> Any comment, suggestion, etc?
>
> Thanks,
> Nuno
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list