This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Issue with sub-object __builtin_object_size
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Ulrich Weigand <uweigand at de dot ibm dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 10 Jun 2014 19:50:02 +0200
- Subject: Re: Issue with sub-object __builtin_object_size
- Authentication-results: sourceware.org; auth=none
- References: <201406101737 dot s5AHbohK017215 at d06av02 dot portsmouth dot uk dot ibm dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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 __builtin_object_size ((struct pollfd *)myfd, 1);
> }
>
> ends up returning 8 from the "test" routine, not 80.
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; };
struct Pollfd myfd[10];
int test (void)
{
return __builtin_object_size (&myfd[0].something, 1);
}
and returning 8 in that case is completely correct.
So the question is why instead of a simple cast it created
ADDR_EXPR of a FIELD_DECL instead.
Jakub