<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 5/23/12 12:54 PM, Nuno Lopes wrote:
<blockquote
cite="mid:20120523185454.Horde.pU8nMJIzaPJPvSRu5W9zNbA@mail.sapo.pt"
type="cite">Hi,
<br>
<br>
Please find in attach a patch that implements the attribute
alloc_size. This attribute was introduced with GCC 4.3.
<br>
<br>
Intended usage:
<br>
<br>
void* my_malloc(size_t) __attribute__((alloc_size(1)));
<br>
void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2)));
<br>
void* my_realloc(void*, size_t) __attribute__((alloc_size(2)));
<br>
<br>
The attribute basically declares that a function returns memory of
size given by the product of the parameters listed in the
attribute.
<br>
</blockquote>
<br>
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).<br>
<br>
That said, we need a way to represent this information within the
LLVM IR in order for it to be useful.<br>
<br>
-- John T.<br>
<br>
<blockquote
cite="mid:20120523185454.Horde.pU8nMJIzaPJPvSRu5W9zNbA@mail.sapo.pt"
type="cite">
<br>
More info:
<a class="moz-txt-link-freetext" href="http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html">http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html</a>
<br>
<br>
This patch only adds Sema support for the attribute. Wiring for
codegen and static analyzer will come later.
<br>
<br>
Any comments, suggestions, etc?
<br>
<br>
Thanks,
<br>
Nuno
<br>
<br>
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.
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>