https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121000
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Qing Zhao <qinz...@gcc.gnu.org>: https://gcc.gnu.org/g:1cf8d08a977f528c6e81601b7586ccf8bc8aa2a6 commit r16-2180-g1cf8d08a977f528c6e81601b7586ccf8bc8aa2a6 Author: Qing Zhao <qing.z...@oracle.com> Date: Wed Jul 9 20:10:30 2025 +0000 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.