]> git.ipfire.org Git - thirdparty/gcc.git/commit
Passing TYPE_SIZE_UNIT of the element as the 6th argument to .ACCESS_WITH_SIZE (PR121000)
authorQing Zhao <qing.zhao@oracle.com>
Wed, 9 Jul 2025 20:10:30 +0000 (20:10 +0000)
committerQing Zhao <qing.zhao@oracle.com>
Thu, 10 Jul 2025 20:31:17 +0000 (20:31 +0000)
commit1cf8d08a977f528c6e81601b7586ccf8bc8aa2a6
tree643ce825dfcef71943b10f045a082f7fd9f6e29a
parentca034694757f0fb3461a1d0c22708a3e4c0e40fa
Passing TYPE_SIZE_UNIT of the element as the 6th argument to .ACCESS_WITH_SIZE (PR121000)

The size of the element of the FAM _cannot_ reliably depends on the original
TYPE of the FAM that we passed as the 6th parameter to the .ACCESS_WITH_SIZE:

     TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (gimple_call_arg (call, 5))))

when the element of the FAM has a variable length type. Since the variable
 that represents TYPE_SIZE_UNIT has no explicit usage in the original IL,
compiler transformations (such as DSE) that are applied before object_size
phase might eliminate the whole definition to the variable that represents
the TYPE_SIZE_UNIT of the element of the FAM.

In order to resolve this issue, instead of passing the original TYPE of the
FAM as the 6th argument to .ACCESS_WITH_SIZE, we should explicitly pass the
original TYPE_SIZE_UNIT of the element TYPE of the FAM as the 6th argument
to the call to  .ACCESS_WITH_SIZE.

PR middle-end/121000

gcc/c/ChangeLog:

* c-typeck.cc (build_access_with_size_for_counted_by): Update comments.
Pass TYPE_SIZE_UNIT of the element as the 6th argument.

gcc/ChangeLog:

* internal-fn.cc (expand_ACCESS_WITH_SIZE): Update comments.
* internal-fn.def (ACCESS_WITH_SIZE): Update comments.
* tree-object-size.cc (access_with_size_object_size): Update comments.
Get the element_size from the 6th argument directly.

gcc/testsuite/ChangeLog:

* gcc.dg/flex-array-counted-by-pr121000.c: New test.
gcc/c/c-typeck.cc
gcc/internal-fn.cc
gcc/internal-fn.def
gcc/testsuite/gcc.dg/flex-array-counted-by-pr121000.c [new file with mode: 0644]
gcc/tree-object-size.cc