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

--- Comment #43 from Bill Wendling <isanbard at gmail dot com> ---
(In reply to qinzhao from comment #40)
> Note, our original purpose of adding this new builtin is explicitly
> described in description section as:
> 
> with the new builtin, "structs can gain the counted_by attribute without
> needing additional open-coded counter assignments for each struct". that
> will ease the adoption of "counted-by" attribute in the large application
> like linux kernel. 
> 
> the above second code segment clearly is a open-coded usage of the
> counted-by field.

I understand that it would be a convenience for large adaptations. My point is
that, unless the 'count' field exists solely for the sanitizer's use, it must
be set no matter what. And since the builtin Kees is asking for could
potentially turn into a no-op, that means to me that an explicit setting of the
'count' field should always occur (unless it's solely for the sanitizer's use).
What this feature would help alleviate are issues like this:

  struct foo *p = alloc (... + sizeof (<typeof FAM>) * count);

  for (int idx = 0; idx < count; ++idx)
    p->FAM[idx] = 42; /* sanitizer error: p->count hasn't been set yet */

  p->count = count; /* this should be done first */

This is a pain point, because I'm sure not everyone tests sanitizer builds. But
a good buildbot farm (testing sanitizer builds) with some helpful warnings
could alleviate some of that pain.

Reply via email to