[cfe-dev] __attribute__((alloc_size(foo))

John Criswell criswell at illinois.edu
Wed May 23 12:16:56 PDT 2012

On 5/23/12 12:54 PM, Nuno Lopes wrote:
> Hi,
> Please find in attach a patch that implements the attribute 
> alloc_size. This attribute was introduced with GCC 4.3.
> Intended usage:
> void* my_malloc(size_t) __attribute__((alloc_size(1)));
> void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2)));
> void* my_realloc(void*, size_t) __attribute__((alloc_size(2)));
> The attribute basically declares that a function returns memory of 
> size given by the product of the parameters listed in the attribute.

I'll throw my two cents in and say that this feature would also be 
useful for projects like SAFECode that, in general, will work with any 
language but need to know specific information about memory allocators 
(including a way to determine the size of the allocation).

That said, we need a way to represent this information within the LLVM 
IR in order for it to be useful.

-- John T.

> More info: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
> This patch only adds Sema support for the attribute. Wiring for 
> codegen and static analyzer will come later.
> Any comments, suggestions, etc?
> Thanks,
> Nuno
> P.S.: This attribute is not expressive enough for functions that e.g. 
> return x elements, like 'alloc_foo_objects(int howmany)'. However, 
> since gcc already has this attribute and software out there is already 
> using it, I think we should support it, even if we come up with a 
> better attribute later.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120523/a77166d3/attachment.html>

More information about the cfe-dev mailing list