nunoplopes at sapo.pt
Wed May 23 13:49:25 PDT 2012
Ah, that's unfortunate; I completely missed Xi Wang's patches.
They are both pretty similar in code and in functionality, though.
P.S.: Actually I like you proposal to accept sizeof exprs on par with
argument numbers. But I agree, let's get this patch in first, and
extend it later.
Citando Jordan Rose <jediknil at belkadan.com>:
> 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