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

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

After discussing with Bill on the Clang side, I confirmed that Clang does not
have the same builtin __builtin_has_attributes as in GCC. So, in order to keep
the user interface consistent between these two compilers. the new
__builtin_get_counted_by is defined as following:

Builtin-in Function: type __builtin_get_counted_by (ptr) 

The built-in function __builtin_get_counted_by checks whether the array object
pointed by the pointer PTR has another object associated with it that
represents the number of elements in the array object through counted_by
attribute (i.e, the counted-by object). If so, returns a pointer to the
corresponding counted-by object. If such counted-by object does not exist,
return a NULL pointer.

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

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

However, for the following:

  struct foo2 {
    int other;
    struct bar2 array[];
  } *q;

  __builtin_get_counted_by (p->array)

returns NULL.

Reply via email to