]> git.ipfire.org Git - thirdparty/gcc.git/commit
Extend "counted_by" attribute to pointer fields of structures. Convert a pointer...
authorQing Zhao <qing.zhao@oracle.com>
Mon, 16 Jun 2025 17:54:24 +0000 (17:54 +0000)
committerQing Zhao <qing.zhao@oracle.com>
Tue, 1 Jul 2025 20:21:37 +0000 (20:21 +0000)
commit687727375769dd41971bad369f3553f1163b3e7a
treeb8c99325c78095e80c1413aaf049256d2b58becb
parentfc029f5d34168ca5d94f737ee5e013f9524c29b2
Extend "counted_by" attribute to pointer fields of structures. Convert a pointer reference with counted_by attribute to .ACCESS_WITH_SIZE.

For example:

struct PP {
  size_t count2;
  char other1;
  char *array2 __attribute__ ((counted_by (count2)));
  int other2;
} *pp;

specifies that the "array2" is an array that is pointed by the
pointer field, and its number of elements is given by the field
"count2" in the same structure.

gcc/c-family/ChangeLog:

* c-attribs.cc (handle_counted_by_attribute): Accept counted_by
attribute for pointer fields.

gcc/c/ChangeLog:

* c-decl.cc (verify_counted_by_attribute): Change the 2nd argument
to a vector of fields with counted_by attribute. Verify all fields
in this vector.
(finish_struct): Collect all the fields with counted_by attribute
to a vector and pass this vector to verify_counted_by_attribute.
* c-typeck.cc (build_counted_by_ref): Handle pointers with counted_by.
Add one more argument, issue error when the pointee type is a structure
or union including a flexible array member.
(build_access_with_size_for_counted_by): Handle pointers with counted_by.
(handle_counted_by_for_component_ref): Call build_counted_by_ref
with the new prototype.

gcc/ChangeLog:

* doc/extend.texi: Extend counted_by attribute to pointer fields in
structures. Add one more requirement to pointers with counted_by
attribute.

gcc/testsuite/ChangeLog:

* gcc.dg/flex-array-counted-by.c: Update test.
* gcc.dg/pointer-counted-by-1.c: New test.
* gcc.dg/pointer-counted-by-2.c: New test.
* gcc.dg/pointer-counted-by-3.c: New test.
* gcc.dg/pointer-counted-by.c: New test.
gcc/c-family/c-attribs.cc
gcc/c/c-decl.cc
gcc/c/c-typeck.cc
gcc/doc/extend.texi
gcc/testsuite/gcc.dg/flex-array-counted-by.c
gcc/testsuite/gcc.dg/pointer-counted-by-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pointer-counted-by-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pointer-counted-by-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pointer-counted-by.c [new file with mode: 0644]