> On Jun 28, 2022, at 12:43 PM, Jakub Jelinek <ja...@redhat.com> wrote:
> 
> On Tue, Jun 28, 2022 at 03:59:22PM +0000, Qing Zhao via Gcc-patches wrote:
>>> On Jun 28, 2022, at 11:08 AM, Jakub Jelinek <ja...@redhat.com> wrote:
>>> 
>>> On Tue, Jun 28, 2022 at 03:03:12PM +0000, Qing Zhao wrote:
>>>> 2. Then replace all “array_at_struct_end_p” with using DECL_NOT_FLEXARRAY 
>>>> in GCC, adding new testing cases
>>> 
>>> No, IMHO array_at_struct_end_p should stay as is, just test this extra flag
>>> too.
>> 
>> Could you please explain why we still need “array_at_struct_end_p” after we 
>> have the DECL_NOT_FLEXARRAY flag in FIELD_DECL?
> 
> Because the flag just tells whether some array shouldn't be treated as (poor 
> man's)
> flexible array member.  We still need to find out if some FIELD_DECL is to
> be treated like a flexible array member, which is a minority of
> COMPONENT_REFs.
> struct S { int a; char b[0]; int c; } s;
> struct T { int d; char e[]; };
> struct U { int f; struct T g; int h; } u;
> Neither s.b nor u.g.e is to be treated like flexible array member,
> no matter what -fstrict-flex-array= option is used.

Then, to resolve this issue, we might need a opposite  flag DECL_IS_FLEXARRAY 
in FIELD_DECL?

The default is FALSE for all FIELD_DECL.

Only when the FIELD_DECL is a flexible array member, FE will set it to TRUE. 

i.e, FE needs to check

        1. The FIELD_DECL is the last field of the enclosing structure;
+      2. This FIELD_DECL is a flexible array per -fstrict-flex-array=n;

Then whenever the DECL_IS_FLEXARRAY is set to TRUE by FEs, that means the 
FIELD_DECL is an flexible array member.  
Middle-end then just use this flag to decide whether an array reference is a 
flexible array  or not.

Any comments?

Qing

> 
>       Jakub
> 

Reply via email to