Re: [PATCH v2 1/2] Compiler Attributes: Add __counted_by_ptr macro

From: Peter Zijlstra

Date: Fri Jan 16 2026 - 03:35:25 EST


On Fri, Nov 21, 2025 at 10:47:45PM +0100, Miguel Ojeda wrote:
> On Fri, Nov 21, 2025 at 8:55 PM Bill Wendling <morbo@xxxxxxxxxx> wrote:
> >
> > +/*
> > + * Optional: only supported since clang >= 21
> > + *
> > + * clang: https://github.com/llvm/llvm-project/pull/137250
> > + */
> > +#ifdef CONFIG_CC_HAS_COUNTED_BY_FOR_POINTER
> > +#define __counted_by_ptr(member) __attribute__((__counted_by__(member)))
> > +#else
> > +#define __counted_by_ptr(member)
> > +#endif
>
> I guess there is a reason for this name, but it sounds to me a bit
> like the thing between parenthesis is a pointer, i.e. that perhaps it
> is the pointee that one that counts.
>
> Hmm... what about `__ptr_counted_by`?

Kees promised to drop this attribute once GCC-16 releases by basically
doing 's/__counted_by_ptr/__counted_by/' and unifying things again.

This split out state will only exist for a very short while until GCC
has a release with this feature on.