[all-commits] [llvm/llvm-project] 745271: [NFC][BoundsSafety] Give `counted_by_or_null`, `si...

Dan Liew via All-commits all-commits at lists.llvm.org
Tue Aug 4 14:47:14 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 745271fc23fd23f83eace959285abfd580a267a5
      https://github.com/llvm/llvm-project/commit/745271fc23fd23f83eace959285abfd580a267a5
  Author: Dan Liew <dan at su-root.co.uk>
  Date:   2026-08-04 (Tue, 04 Aug 2026)

  Changed paths:
    M clang/docs/BoundsSafetyImplPlans.md
    M clang/include/clang/Basic/Attr.td
    M clang/include/clang/Basic/AttrDocs.td

  Log Message:
  -----------
  [NFC][BoundsSafety] Give `counted_by_or_null`, `sized_by`, and `sized_by_or_null` their own documentation (#212877)

Previously the `counted_by`, `counted_by_or_null`, `sized_by`, and
`sized_by_or_null` attributes all pointed at a single `Documentation`
object (`CountedByDocs`). The generated `AttributeReference.rst`
therefore folded all four into one entry whose text described only
`counted_by` used on a C99 flexible array member.

This was misleading because the attributes differ in important ways that
went undocumented:

* `counted_by` counts *elements* whereas `sized_by` counts *bytes*.
* `counted_by` and `sized_by` require a null pointer to have a zero
count/size, while the `_or_null` variants allow a null pointer
regardless of the count or size.
* `counted_by` may be applied to a flexible array member, but
`sized_by`, `counted_by_or_null`, and `sized_by_or_null` apply to
pointers only.

As a result a reader looking up any of the three non-`counted_by`
attributes was shown documentation for a different attribute with
different behavior.

This change gives `sized_by`, `counted_by_or_null`, and
`sized_by_or_null` their own documentation so that each renders as its
own entry describing its actual behavior. The substantive text lives in
`counted_by` and `sized_by`; the `_or_null` variants are described in
terms of their base attribute.

While we're here, this patch also:

* Restructures `counted_by`'s documentation to explain the attribute's
meaning first, with the flexible-array-member material moved into its
own sub-section rather than leading the entry. It made sense that FAMs
were the leading entry when that was the only context the attribute was
supported in, but it's also now supported on pointer fields in a struct.
* Discusses how `counted_by` on `void *` is supported as a GNU
extension.
* Adds two sections on keeping the pointer and count/size value in sync.
The two sections are practically identical other than the attribute they
discuss and the associated count/size.
* For `counted_by`, explains how a pointer to a forward-declared type is
allowed as long as the type is complete at the use sites.
* For `sized_by`, explains the motivation for using it on types that
aren't byte-sized.

Assisted-by: Claude Code

rdar://136979310



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list