[cfe-dev] [PATCH RFC] add support to alloc_size attribute

Eli Friedman eli.friedman at gmail.com
Wed Feb 22 17:10:45 PST 2012


On Wed, Feb 22, 2012 at 4:30 PM, Xi Wang <xi.wang at gmail.com> wrote:
> Hi,
>
> Attached is a proposed patch that adds support to the alloc_size attribute.
>
> http://llvm.org/bugs/show_bug.cgi?id=10516

Quick review:

+  unsigned* start = &AllocSizeArgs[0];
+  unsigned size = AllocSizeArgs.size();
+  llvm::array_pod_sort(start, start + size);

Don't you need to check for duplicates?  Also, for an alloc_size
attribute which doesn't specify any indexes?

+    // Is the function argument an integer type?
+    QualType T = getFunctionOrMethodArgType(D, x).getNonReferenceType();

I don't think you want to allow applying alloc_size to arguments of type "int&".

+    unsigned x = (unsigned) ArgNum.getZExtValue();

This is unsafe; there's no guarantee ArgNum fits into a 64-bit integer
(which will cause an assert), and you're masking off the top 32 bits
of that 64-bit integer without any additional checks.  You should
perform the bounds checking on the APSInt, and then perform whatever
conversion is necessary.  (And if this is copied from existing cod
which does the same thing, please fix that as well.)

-Eli



More information about the cfe-dev mailing list