This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/77301] __builtin_object_size incorrect for an array in a struct referenced by a pointer


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]