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

--- Comment #7 from qinzhao at gcc dot gnu.org ---
I need to modify the testing case as following to enable
__builtin_dynamic_object_size working as expected:

/* The parameter m must be const qualified to avoid the m is 
   marked as TREE_SIDE_EFFECTS in IR.
   The __builtin_dynamic_object_size will be folded as -1 by
   fold_builtin_object_size when m is NOT const qualified.  */

void
foo (int n, const 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;
  EXPECT (__builtin_dynamic_object_size (p->b, 1), sizeof (A) * n);
}

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

Reply via email to