nunoplopes at sapo.pt
Wed May 23 17:24:43 PDT 2012
Thank you both,
Citando Xi Wang <xi.wang at gmail.com>:
> Thanks for letting me know. I am happy to see alloc_size in Clang. ;-)
> Also thanks to Nuno for bringing this up.
> - xi
> On May 23, 2012, at 3:29 PM, Jordan Rose wrote:
>> Xi Wang took a stab at this back in February but no one finished
>> reviewing his patch. I'll take a look at yours soon, but
>> maybe Xi has an opinion as well?
>> P.S. If we want to go really crazy, alloc_foo_objects(int howmany)
>> could be handled with an extension to alloc_size:
>> __attribute__((alloc_size(1,sizeof(struct foo)))). But that can
>> wait for later.
>> : http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-February/019952.html
>> On May 23, 2012, at 13:54, Nuno Lopes wrote:
>>> 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.
>>> 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?
>>> 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.
More information about the cfe-dev