Re: Issue with sub-object __builtin_object_size

2014-09-17 Thread Ulrich Weigand
Jason Merrill wrote: > Well, __builtin_object_size seems to be pretty fragile magic. To make > it work I guess you could add a wrapper for poll that takes a Pollfd and > does a reinterpret_cast, i.e. > > inline int poll(Pollfd* p, nfds_t n, int t) > { >return poll(reinterpret_cast(p), n, t

Re: Issue with sub-object __builtin_object_size

2014-09-16 Thread Jason Merrill
On 09/16/2014 08:27 AM, Jason Merrill wrote: On 09/16/2014 06:23 AM, Ulrich Weigand wrote: Note that with a somewhat equivalent C construct: struct pollfd { int fd; short int events; short int revents; }; struct Pollfd { struct pollfd x; }; struct Pollfd myfd[1

Re: Issue with sub-object __builtin_object_size

2014-09-16 Thread Ulrich Weigand
Jason Merrill wrote: > On 09/16/2014 06:23 AM, Ulrich Weigand wrote: > > Now in this case, we cast a pointer to the array to a pointer to a base > > type of the array element type -- but the intent is for the pointer to still > > refer to the whole array. (Of course, this only works if the base ty

Re: Issue with sub-object __builtin_object_size

2014-09-16 Thread Jason Merrill
On 09/16/2014 06:23 AM, Ulrich Weigand wrote: I guess I'm still a bit confused about the special handling of the array case. Even with the last bit set, array elements normally do not count as "subobjects", so __builtin_object_size still returns the size of the full array. I expect that's beca

Re: Issue with sub-object __builtin_object_size

2014-09-16 Thread Ulrich Weigand
Jason Merrill wrote: > On 09/15/2014 11:55 AM, Ulrich Weigand wrote: > > (https://gcc.gnu.org/ml/gcc/2014-06/msg00116.html) > > > From the __builtin_object_size documentation, it's not immediately > > clear to me whether this is supposed to work or not: > > > >If the least significant > >b

Re: Issue with sub-object __builtin_object_size

2014-09-15 Thread Jason Merrill
On 09/15/2014 11:55 AM, Ulrich Weigand wrote: (https://gcc.gnu.org/ml/gcc/2014-06/msg00116.html) From the __builtin_object_size documentation, it's not immediately clear to me whether this is supposed to work or not: If the least significant bit is clear, objects are whole variables, if

Re: Issue with sub-object __builtin_object_size

2014-09-15 Thread Ulrich Weigand
Jason Merrill wrote: > On 09/15/2014 11:21 AM, Ulrich Weigand wrote: > > Jakub Jelinek wrote: > >> On Tue, Jun 10, 2014 at 07:37:50PM +0200, Ulrich Weigand wrote: > >>> the following C++ test case: > >>> > >>> struct pollfd > >>>{ > >>> int fd; > >>> short int events; > >>> short

Re: Issue with sub-object __builtin_object_size

2014-09-15 Thread Jason Merrill
On 09/15/2014 11:21 AM, Ulrich Weigand wrote: Jakub Jelinek wrote: On Tue, Jun 10, 2014 at 07:37:50PM +0200, Ulrich Weigand wrote: the following C++ test case: struct pollfd { int fd; short int events; short int revents; }; struct Pollfd : public pollfd { }; struct Pollf

Re: Issue with sub-object __builtin_object_size

2014-09-15 Thread Jakub Jelinek
On Mon, Sep 15, 2014 at 05:21:50PM +0200, Ulrich Weigand wrote: > > The thing is that the C++ FE transforms this kind of cast to > > &((struct Pollfd *) &myfd)->D.2233 > > so for middle-end where __builtin_object_size is evaluated this > > is like: > > struct Pollfd { struct pollfd something; }; >

Re: Issue with sub-object __builtin_object_size

2014-09-15 Thread Ulrich Weigand
Jakub Jelinek wrote: > On Tue, Jun 10, 2014 at 07:37:50PM +0200, Ulrich Weigand wrote: > > the following C++ test case: > > > > struct pollfd > > { > > int fd; > > short int events; > > short int revents; > > }; > > > > struct Pollfd : public pollfd { }; > > > > struct Pollfd myf

Re: Issue with sub-object __builtin_object_size

2014-06-10 Thread Jakub Jelinek
On Tue, Jun 10, 2014 at 07:37:50PM +0200, Ulrich Weigand wrote: > the following C++ test case: > > struct pollfd > { > int fd; > short int events; > short int revents; > }; > > struct Pollfd : public pollfd { }; > > struct Pollfd myfd[10]; > > int test (void) > { > return __bu

Issue with sub-object __builtin_object_size

2014-06-10 Thread Ulrich Weigand
Hello, the following C++ test case: struct pollfd { int fd; short int events; short int revents; }; struct Pollfd : public pollfd { }; struct Pollfd myfd[10]; int test (void) { return __builtin_object_size ((struct pollfd *)myfd, 1); } ends up returning 8 from the "test" rou