[all-commits] [llvm/llvm-project] f29955: [Clang][Sema] Allow counted_by on void* as GNU ext...

Kees Cook via All-commits all-commits at lists.llvm.org
Thu Nov 6 19:10:57 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f29955a594aedf5943d492a999b83e8c6b8fafae
      https://github.com/llvm/llvm-project/commit/f29955a594aedf5943d492a999b83e8c6b8fafae
  Author: Kees Cook <kees at kernel.org>
  Date:   2025-11-06 (Thu, 06 Nov 2025)

  Changed paths:
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/CodeGen/CGBuiltin.cpp
    M clang/lib/Sema/SemaBoundsSafety.cpp
    A clang/test/CodeGen/attr-counted-by-void-ptr-gnu.c
    M clang/test/Sema/attr-counted-by-late-parsed-struct-ptrs.c
    M clang/test/Sema/attr-counted-by-or-null-last-field.c
    M clang/test/Sema/attr-counted-by-or-null-late-parsed-struct-ptrs.c
    M clang/test/Sema/attr-counted-by-or-null-struct-ptrs.c
    M clang/test/Sema/attr-counted-by-struct-ptrs.c
    A clang/test/Sema/attr-counted-by-void-ptr-gnu.c

  Log Message:
  -----------
  [Clang][Sema] Allow counted_by on void* as GNU extension (#164737)

The counted_by attribute currently rejects void* members because void
has no defined size. However, the sized_by attribute accepts void* since
it explicitly measures bytes. As a GNU extension, void pointer
arithmetic treats void as having size 1 byte, so counted_by on void*
should behave identically to sized_by (treating the count as bytes).

Allow counted_by on void* as a GNU extension. The implementation
validates this only at declaration time in SemaBoundsSafety.cpp,
emitting a -Wpointer-arith warning that the attribute is treated as a
GNU extension equivalent to sized_by. Both use-site validation and code
generation trust this earlier validation, avoiding redundant checks.

In CodeGen, __builtin_dynamic_object_size now correctly handles
counted_by on void* by treating any CountAttributedType with zero
element size as having 1-byte elements, matching the GNU void pointer
arithmetic semantics.

Add tests validating both Sema diagnostics and CodeGen behavior (correct
byte counts from __builtin_dynamic_object_size). Update existing
counted_by tests to explicitly use -Wpointer-arith to preserve their
original intent of rejecting void* in strict C mode.



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