> On Jul 10, 2025, at 12:34, Jakub Jelinek <ja...@redhat.com> wrote:
>
> On Thu, Jul 10, 2025 at 04:03:29PM +0000, Qing Zhao wrote:
>> 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.
>>
>> The patches have been bootstrapped and regression tested on both aarch64
>> and x86.
>>
>> Okay for trunk?
>>
>> thanks.
>>
>> Qing
>>
>> PR middle-end/121000
>>
>> gcc/c/ChangeLog:
>>
>> * c-typeck.cc (build_counted_by_ref): Update comments.
>
> You can't trust mklog that much.
Oh, thanks for reminding me on this.
Yes, I just checked, you are right. I will check and update the changelog
accordingly.
> You're updating
> build_access_with_size_for_counted_by function comment, not
> build_counted_by_ref comments.
>
>> (build_access_with_size_for_counted_by): Pass TYPE_SIZE_UNIT of the
>> element as the 6th argument.
>>
>> gcc/ChangeLog:
>>
>> * internal-fn.cc (expand_DEFERRED_INIT): Update comments.
>> * internal-fn.def (DEFERRED_INIT): Update comments.
>
> Nor these two. It is expand_ACCESS_WITH_SIZE and ACCESS_WITH_SIZE
> in these cases.
Will update.
>
>> * 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.
>
> Otherwise LGTM with one nit.
>> +int main ()
>
> Line break before main.
Okay, will fix this before committing.
Thanks a lot.
Qing
>
> Jakub