This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/77301] __builtin_object_size incorrect for an array in a struct referenced by a pointer
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 19 Aug 2016 18:12:32 +0000
- Subject: [Bug middle-end/77301] __builtin_object_size incorrect for an array in a struct referenced by a pointer
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
- References: <bug-77301-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77301
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thanks. As surprising as that seems, it would explain the output of the test
case in comment #0, even though it's not at all obvious from the manual.
But if change the test case like below I get three different results. The
latter two don't jibe with my understanding of your explanation, or seem
correct (or desirable/safe) to me.
$ cat z.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -O2
-Wall -Wextra z.c && ./a.out
struct A {
char a [4];
void (*pf)(void);
} a [2];
int main (void)
{
struct A* p = __builtin_malloc (sizeof (struct A) * 2);
__builtin_printf ("%zi %zi %zi %zi\n",
__builtin_object_size (a->a, 0),
__builtin_object_size (a->a, 1),
__builtin_object_size (a->a, 2),
__builtin_object_size (a->a, 3));
__builtin_printf ("%zi %zi %zi %zi\n",
__builtin_object_size (p->a, 0),
__builtin_object_size (p->a, 1),
__builtin_object_size (p->a, 2),
__builtin_object_size (p->a, 3));
__builtin_printf ("%zi %zi %zi %zi\n",
__builtin_object_size (p->a + 1, 0),
__builtin_object_size (p->a + 1, 1),
__builtin_object_size (p->a + 1, 2),
__builtin_object_size (p->a + 1, 3));
}
32 32 32 32
32 4 32 4
31 3 31 31