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 because there isn't an easy way to distinguish between
the array and the first element.
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 type
is actually the same size as the array type.)
And I'm arguing that this intent is not well expressed by the code. :)
If they want to refer to the whole array, why are they casting the
pointer to a different type? And why are they passing the "subobject
only" value as the second argument?
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[10];
we still get an object size of 80 for either:
__builtin_object_size ((struct pollfd *)myfd, 1);
or even
__builtin_object_size (&myfd->x, 1);
That strikes me as a bug, especially the second one.
Jason