[all-commits] [llvm/llvm-project] 9ae3bc: [Clang][counted_by] Add support for 'counted_by' o...

Bill Wendling via All-commits all-commits at lists.llvm.org
Tue May 13 16:01:58 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9ae3bce17543f92ce0237597cc66503d58cce317
      https://github.com/llvm/llvm-project/commit/9ae3bce17543f92ce0237597cc66503d58cce317
  Author: Bill Wendling <morbo at google.com>
  Date:   2025-05-13 (Tue, 13 May 2025)

  Changed paths:
    M clang/lib/CodeGen/CGBuiltin.cpp
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/CodeGen/CodeGenFunction.h
    A clang/test/CodeGen/attr-counted-by-for-pointers.c
    M clang/test/CodeGen/attr-counted-by.c

  Log Message:
  -----------
  [Clang][counted_by] Add support for 'counted_by' on struct pointers (#137250)

The 'counted_by' attribute is now available for pointers in structs.
It generates code for sanity checks as well as
__builtin_dynamic_object_size()
calculations. For example:

  struct annotated_ptr {
    int count;
    char *buf __attribute__((counted_by(count)));
  };

If the pointer's type is 'void *', use the 'sized_by' attribute, which
works similarly to 'counted_by', but can handle the 'void' base type:

  struct annotated_ptr {
    int count;
    void *buf __attribute__((sized_by(count)));
  };

If the 'count' field member occurs after the pointer, use the
'-fexperimental-late-parse-attributes' flag during compilation.

Note that 'counted_by' cannot be applied to a pointer to an incomplete
type, because the size isn't known.

  struct foo;
  struct annotated_ptr {
    int count;
    struct foo *buf __attribute__((counted_by(count))); /* invalid */
  };

Signed-off-by: Bill Wendling <morbo at google.com>



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