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

--- Comment #60 from qinzhao at gcc dot gnu.org ---
I came up with the following draft for the documentation of the new
__builtin_get_counted_by, let me know your comments and suggestions:

Builtin-in Function: type __builtin_get_counted_by (ptr)

The argument PTR to the built-in function __builtin_get_counted_by is a pointer
to an array object, which should have a counted_by attribute associated with
it. This function returns a pointer to the corresponding object that holds the
number of elements in the array object through counted_by attribute.

The TYPE of the returned value should be a pointer type pointing to an integral
type.

It's the user's responsibility to make sure that the PTR has a counted-by
attribute associated with it.

(GCC provides another built-in __builtin_has_attribute() to make sure this)

For example:

for the following:

  struct foo {
    int counter;
    struct bar1 array[] __attribute__((counted_by(counter)));
  } *p;

  __builtin_get_counted_by (p->array)

returns:

  &p->counter

Reply via email to