https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121000

            Bug ID: 121000
           Summary: __builtin_dynamic_object_size should work for FAM with
                    VLA element when annotated with counted_by
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qinzhao at gcc dot gnu.org
  Target Milestone: ---

for the following testing case:

void
foo (int n, int m)
{
 typedef int A[m];
 struct S { int n, m; A a[2]; A b[] __attribute__((counted_by (n))); } *p;
 p = __builtin_malloc (sizeof (struct S) + sizeof (A) * n);
 p->n = n;
 p->m = m;
 __builtin_printf ("the bdos of pb is %u \n",__builtin_dynamic_object_size
(p->b, 1));
}

int main ()
{
  foo (2, 10);
  return 0;
}

compiled with the latest GCC, the bdos cannot return the correct value for the
object size of p->b. 

/home/opc/Install/latest-d/bin/gcc -O1 t.c
the bdos of pb is 0 

However, when change the above testing slightly to change the VLA to a regular
array:

void
foo (int n, int m)
{
 typedef int A[10];
 struct S { int n, m; A a[2]; A b[] __attribute__((counted_by (n))); } *p;
 p = __builtin_malloc (sizeof (struct S) + sizeof (A) * n);
 p->n = n;
 p->m = m;
 __builtin_printf ("the bdos of pb is %u \n",__builtin_dynamic_object_size
(p->b, 1));
}

int main ()
{
  foo (2, 10);
  return 0;
}

the bdos returned correct value:

/home/opc/Install/latest-d/bin/gcc -O1 t.c
the bdos of pb is 80

Reply via email to