[LLVMdev] alloc_size metadata
Nuno Lopes
nunoplopes at sapo.pt
Wed May 23 16:16:30 PDT 2012
Hi,
I'm implementing the alloc_size function attribute in clang. 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
More information about the llvm-dev
mailing list