[cfe-dev] Addition of function parameter attribute to help __builtin_object_size

George Burgess IV via cfe-dev cfe-dev at lists.llvm.org
Mon Sep 14 11:33:26 PDT 2015


It's more or less meant to be implemented by passing extra arguments, which
changes how the function is called. This is also meant to work across TUs.
e.g. in

// foo.h
int doIt(void *const p __attribute__((carry_size(0))));

// foo.c
int doIt(void *const p __attribute__((carry_size(0)))) { return
__builtin_object_size(p, 0); }

// main.c
#include "foo.h"
int main() {
  char c[10];
  return doIt(c);
}

Also, the common case for how this is foreseen to be used is "call function
A with the object size if __builtin_object_size succeeds, and function B if
__builtin_object_size fails," so being able to overload on the attribute
may be mildly convenient. :)

On Mon, Sep 14, 2015 at 11:19 AM, PaX Team <pageexec at gmail.com> wrote:

> On 14 Sep 2015 at 10:54, George Burgess IV via cfe-dev wrote:
>
> > Hello friends,
> >
> > I plan to add a function parameter attribute called carry_size (name
> > suggestions welcome). The goal of this attribute is to help Clang/LLVM
> > answer `__builtin_object_size(Ptr, Type)` calls when the object pointed
> to
> > by Ptr isn't visible in the caller of __builtin_object_size.
> >
> > An example of its use:
> > #define CS(N) __attribute__((carry_size(N)))
> > void __attribute__((noinline)) Func(void *const p CS(0)) {
> >   printf("%d\n", __builtin_object_size(p, 0));
> > }
>
> i must be missing something here but why do you need a manually applied
> attr at all when the compiler can just figure it out itself whenever it
> sees a call to __builtin_object_size?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150914/94b2f024/attachment.html>


More information about the cfe-dev mailing list