Re: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-16 Thread Qing Zhao via Gcc-patches
FYI.

Committed this last patch as:
https://jira.oci.oraclecorp.com/browse/OLDIS-21095

I will come up with the update to gcc-13/changes.html for -fstrict-flex-arrays 
very soon.

Thanks.

Qing
> On Dec 16, 2022, at 9:49 AM, Qing Zhao via Gcc-patches 
>  wrote:
> 
> 
> 
>> On Dec 16, 2022, at 4:17 AM, Richard Biener  wrote:
>> 
>> On Thu, 15 Dec 2022, Qing Zhao wrote:
>> 
>>> 
>>> 
 On Dec 15, 2022, at 2:47 AM, Richard Biener  wrote:
 
 On Wed, 14 Dec 2022, Qing Zhao wrote:
 
> Hi, Richard,
> 
> I guess that we now agreed on the following:
> 
> “ the information that we ran into a trailing array but didn't consider 
> it a flex array because of -fstrict-flex-arrays is always a useful 
> information”
> 
> The only thing we didn’t decide is:
> 
> A. Amend such new information to -Warray-bounds when 
> -fstrict-flex-arrays=N (N>0) specified.
> 
> OR
> 
> B. Issue such new information with a new warning option 
> -Wstrict-flex-arrays when -fstrict-flex-arrays=N (N>0) specified.
> 
> My current patch implemented B. 
 
 Plus it implements it to specify a different flex-array variant for
 the extra diagnostic.
>>> Could you clarify a little bit on this? (Don’t quite understand…)
 
> If you think A is better, I will change the patch as A. 
 
 I would tend to A since, as I said, it's useful information that
 shouldn't be hidden and not adding an option removes odd combination
 possibilities such as -Wno-array-bounds -Wstrict-flex-arrays.
>>> 
>>> With current implementation, the above combination will ONLY report the 
>>> misuse of trailing array as flex-array.  No out-of-bounds warnings 
>>> issued.
>>> 
 In particular I find, say, -fstrict-flex-arrays=2 -Wstrict-flex-arrays=1
 hardly useful.
>>> 
>>> The above combination will NOT happen, because there is NO level argument 
>>> for -Wstrict-flex-arrays.
>>> 
>>> The only combination will be:-fstrict-flex-arrays=N -Wstrict-flex-arrays
>>> 
>>> When N > 0, -Wstrict-flex-arrays will report any misuse of trailing arrays 
>>> as flexible array per the value of N.
 
 But I'm interested in other opinions.
>>> 
>>> Adding a separate -Wstrict-flex-arrays will provide users a choice to ONLY 
>>> look at the mis-use of trailing arrays as flex-arrays.  Without this new 
>>> option, such information will be buried into tons of out-of-bounds messges. 
>>> 
>>> I think this is the major benefit to have one separate new warning 
>>> -Wstrict-flex-arrays. 
>>> 
>>> Do we need to provide the users this choice?
>> 
>> Ah, OK - I can see the value of auditing code this way before
>> enabling -fstrict-flex-arrays.
> Yes, I think the major benefit of this option is to help users to identify 
> all the places where the trailing arrays are misused as flex-arrays at 
> different level of -fstrict-flex-arrays=N, then update their source code 
> accordingly. And finally can enable -fstrict-flex-arrays by default.
>> 
>>> +  if (opts->x_warn_strict_flex_arrays)
>>> +if (opts->x_flag_strict_flex_arrays == 0)
>>> +  {
>>> + opts->x_warn_strict_flex_arrays = 0;
>>> + warning_at (UNKNOWN_LOCATION, 0,
>>> + "%<-Wstrict-flex-arrays%> is ignored when"
>>> + " %<-fstrict-flex-arrays%> does not present");
>> 
>> "is not present”.
> Okay.
>> 
>> The patch is OK with that change.
> Thanks! Will commit the patch after the change.
>> 
>> Thanks and sorry for the slow process ...
> 
> Thank you for your patience and questions.
> The discussion is very helpful since I was not 100% sure whether this new 
> warning is necessary or not in the beginning, but now after this discussion I 
> feel confident that it’s a necessary option to be added.
> 
> Qing
> 
>> 
>> Richard.
>> 
>>> Thanks.
>>> 
>>> Qing
 
 Thanks,
 Richard.
 
> Let me know your opinion.
> 
> thanks.
> 
> Qing
> 
> 
>> On Dec 14, 2022, at 4:03 AM, Richard Biener  wrote:
>> 
>> On Tue, 13 Dec 2022, Qing Zhao wrote:
>> 
>>> Richard, 
>>> 
>>> Do you have any decision on this one? 
>>> Do we need this warning option For GCC? 
>> 
>> Looking at the testcases it seems that the diagnostic amends
>> -Warray-bounds diagnostics for trailing but not flexible arrays?
>> Wouldn't it be better to generally diagnose this, so have
>> -Warray-bounds, with -fstrict-flex-arrays, for
>> 
>> struct X { int a[1]; };
>> int foo (struct X *p)
>> {
>> return p->a[1];
>> }
>> 
>> emit
>> 
>> warning: array subscript 1 is above array bounds ...
>> note: the trailing array is only a flexible array member with 
>> -fno-strict-flex-arrays
>> 
>> ?  Having -Wstrict-flex-arrays=N and N not agree with the
>> -fstrict-flex-arrays level sounds hardly useful to me but the
>> information that we ran into a trailing array but didn'

Re: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-16 Thread Qing Zhao via Gcc-patches


> On Dec 16, 2022, at 4:17 AM, Richard Biener  wrote:
> 
> On Thu, 15 Dec 2022, Qing Zhao wrote:
> 
>> 
>> 
>>> On Dec 15, 2022, at 2:47 AM, Richard Biener  wrote:
>>> 
>>> On Wed, 14 Dec 2022, Qing Zhao wrote:
>>> 
 Hi, Richard,
 
 I guess that we now agreed on the following:
 
 “ the information that we ran into a trailing array but didn't consider 
 it a flex array because of -fstrict-flex-arrays is always a useful 
 information”
 
 The only thing we didn’t decide is:
 
 A. Amend such new information to -Warray-bounds when 
 -fstrict-flex-arrays=N (N>0) specified.
 
 OR
 
 B. Issue such new information with a new warning option 
 -Wstrict-flex-arrays when -fstrict-flex-arrays=N (N>0) specified.
 
 My current patch implemented B. 
>>> 
>>> Plus it implements it to specify a different flex-array variant for
>>> the extra diagnostic.
>> Could you clarify a little bit on this? (Don’t quite understand…)
>>> 
 If you think A is better, I will change the patch as A. 
>>> 
>>> I would tend to A since, as I said, it's useful information that
>>> shouldn't be hidden and not adding an option removes odd combination
>>> possibilities such as -Wno-array-bounds -Wstrict-flex-arrays.
>> 
>> With current implementation, the above combination will ONLY report the 
>> misuse of trailing array as flex-array.  No out-of-bounds warnings 
>> issued.
>> 
>>> In particular I find, say, -fstrict-flex-arrays=2 -Wstrict-flex-arrays=1
>>> hardly useful.
>> 
>> The above combination will NOT happen, because there is NO level argument 
>> for -Wstrict-flex-arrays.
>> 
>> The only combination will be:-fstrict-flex-arrays=N -Wstrict-flex-arrays
>> 
>> When N > 0, -Wstrict-flex-arrays will report any misuse of trailing arrays 
>> as flexible array per the value of N.
>>> 
>>> But I'm interested in other opinions.
>> 
>> Adding a separate -Wstrict-flex-arrays will provide users a choice to ONLY 
>> look at the mis-use of trailing arrays as flex-arrays.  Without this new 
>> option, such information will be buried into tons of out-of-bounds messges. 
>> 
>> I think this is the major benefit to have one separate new warning 
>> -Wstrict-flex-arrays. 
>> 
>> Do we need to provide the users this choice?
> 
> Ah, OK - I can see the value of auditing code this way before
> enabling -fstrict-flex-arrays.
Yes, I think the major benefit of this option is to help users to identify all 
the places where the trailing arrays are misused as flex-arrays at different 
level of -fstrict-flex-arrays=N, then update their source code accordingly. And 
finally can enable -fstrict-flex-arrays by default.
> 
>> +  if (opts->x_warn_strict_flex_arrays)
>> +if (opts->x_flag_strict_flex_arrays == 0)
>> +  {
>> + opts->x_warn_strict_flex_arrays = 0;
>> + warning_at (UNKNOWN_LOCATION, 0,
>> + "%<-Wstrict-flex-arrays%> is ignored when"
>> + " %<-fstrict-flex-arrays%> does not present");
> 
> "is not present”.
Okay.
> 
> The patch is OK with that change.
Thanks! Will commit the patch after the change.
> 
> Thanks and sorry for the slow process ...

Thank you for your patience and questions.
The discussion is very helpful since I was not 100% sure whether this new 
warning is necessary or not in the beginning, but now after this discussion I 
feel confident that it’s a necessary option to be added.

Qing

> 
> Richard.
> 
>> Thanks.
>> 
>> Qing
>>> 
>>> Thanks,
>>> Richard.
>>> 
 Let me know your opinion.
 
 thanks.
 
 Qing
 
 
> On Dec 14, 2022, at 4:03 AM, Richard Biener  wrote:
> 
> On Tue, 13 Dec 2022, Qing Zhao wrote:
> 
>> Richard, 
>> 
>> Do you have any decision on this one? 
>> Do we need this warning option For GCC? 
> 
> Looking at the testcases it seems that the diagnostic amends
> -Warray-bounds diagnostics for trailing but not flexible arrays?
> Wouldn't it be better to generally diagnose this, so have
> -Warray-bounds, with -fstrict-flex-arrays, for
> 
> struct X { int a[1]; };
> int foo (struct X *p)
> {
> return p->a[1];
> }
> 
> emit
> 
> warning: array subscript 1 is above array bounds ...
> note: the trailing array is only a flexible array member with 
> -fno-strict-flex-arrays
> 
> ?  Having -Wstrict-flex-arrays=N and N not agree with the
> -fstrict-flex-arrays level sounds hardly useful to me but the
> information that we ran into a trailing array but didn't consider
> it a flex array because of -fstrict-flex-arrays is always a
> useful information?
> 
> But maybe I misunderstood this new diagnostic?
> 
> Thanks,
> Richard.
> 
> 
>> thanks.
>> 
>> Qing
>> 
>>> On Dec 6, 2022, at 11:18 AM, Qing Zhao  wrote:
>>> 
>>> '-Wstrict-flex-arrays'
>>>  Warn about inproper usages of flexible array members according to

Re: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-16 Thread Richard Biener via Gcc-patches
On Thu, 15 Dec 2022, Qing Zhao wrote:

> 
> 
> > On Dec 15, 2022, at 2:47 AM, Richard Biener  wrote:
> > 
> > On Wed, 14 Dec 2022, Qing Zhao wrote:
> > 
> >> Hi, Richard,
> >> 
> >> I guess that we now agreed on the following:
> >> 
> >> “ the information that we ran into a trailing array but didn't consider 
> >> it a flex array because of -fstrict-flex-arrays is always a useful 
> >> information”
> >> 
> >> The only thing we didn’t decide is:
> >> 
> >> A. Amend such new information to -Warray-bounds when 
> >> -fstrict-flex-arrays=N (N>0) specified.
> >> 
> >> OR
> >> 
> >> B. Issue such new information with a new warning option 
> >> -Wstrict-flex-arrays when -fstrict-flex-arrays=N (N>0) specified.
> >> 
> >> My current patch implemented B. 
> > 
> > Plus it implements it to specify a different flex-array variant for
> > the extra diagnostic.
> Could you clarify a little bit on this? (Don’t quite understand…)
> > 
> >> If you think A is better, I will change the patch as A. 
> > 
> > I would tend to A since, as I said, it's useful information that
> > shouldn't be hidden and not adding an option removes odd combination
> > possibilities such as -Wno-array-bounds -Wstrict-flex-arrays.
> 
> With current implementation, the above combination will ONLY report the 
> misuse of trailing array as flex-array.  No out-of-bounds warnings 
> issued.
> 
> > In particular I find, say, -fstrict-flex-arrays=2 -Wstrict-flex-arrays=1
> > hardly useful.
> 
> The above combination will NOT happen, because there is NO level argument for 
> -Wstrict-flex-arrays.
> 
> The only combination will be:-fstrict-flex-arrays=N -Wstrict-flex-arrays
> 
> When N > 0, -Wstrict-flex-arrays will report any misuse of trailing arrays as 
> flexible array per the value of N.
> > 
> > But I'm interested in other opinions.
> 
> Adding a separate -Wstrict-flex-arrays will provide users a choice to ONLY 
> look at the mis-use of trailing arrays as flex-arrays.  Without this new 
> option, such information will be buried into tons of out-of-bounds messges. 
> 
> I think this is the major benefit to have one separate new warning 
> -Wstrict-flex-arrays. 
> 
> Do we need to provide the users this choice?

Ah, OK - I can see the value of auditing code this way before
enabling -fstrict-flex-arrays.

> +  if (opts->x_warn_strict_flex_arrays)
> +if (opts->x_flag_strict_flex_arrays == 0)
> +  {
> + opts->x_warn_strict_flex_arrays = 0;
> + warning_at (UNKNOWN_LOCATION, 0,
> + "%<-Wstrict-flex-arrays%> is ignored when"
> + " %<-fstrict-flex-arrays%> does not present");

"is not present".

The patch is OK with that change.

Thanks and sorry for the slow process ...

Richard.

> Thanks.
> 
> Qing
> > 
> > Thanks,
> > Richard.
> > 
> >> Let me know your opinion.
> >> 
> >> thanks.
> >> 
> >> Qing
> >> 
> >> 
> >>> On Dec 14, 2022, at 4:03 AM, Richard Biener  wrote:
> >>> 
> >>> On Tue, 13 Dec 2022, Qing Zhao wrote:
> >>> 
>  Richard, 
>  
>  Do you have any decision on this one? 
>  Do we need this warning option For GCC? 
> >>> 
> >>> Looking at the testcases it seems that the diagnostic amends
> >>> -Warray-bounds diagnostics for trailing but not flexible arrays?
> >>> Wouldn't it be better to generally diagnose this, so have
> >>> -Warray-bounds, with -fstrict-flex-arrays, for
> >>> 
> >>> struct X { int a[1]; };
> >>> int foo (struct X *p)
> >>> {
> >>> return p->a[1];
> >>> }
> >>> 
> >>> emit
> >>> 
> >>> warning: array subscript 1 is above array bounds ...
> >>> note: the trailing array is only a flexible array member with 
> >>> -fno-strict-flex-arrays
> >>> 
> >>> ?  Having -Wstrict-flex-arrays=N and N not agree with the
> >>> -fstrict-flex-arrays level sounds hardly useful to me but the
> >>> information that we ran into a trailing array but didn't consider
> >>> it a flex array because of -fstrict-flex-arrays is always a
> >>> useful information?
> >>> 
> >>> But maybe I misunderstood this new diagnostic?
> >>> 
> >>> Thanks,
> >>> Richard.
> >>> 
> >>> 
>  thanks.
>  
>  Qing
>  
> > On Dec 6, 2022, at 11:18 AM, Qing Zhao  wrote:
> > 
> > '-Wstrict-flex-arrays'
> >   Warn about inproper usages of flexible array members according to
> >   the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
> >   the trailing array field of a structure if it's available,
> >   otherwise according to the LEVEL of the option
> >   '-fstrict-flex-arrays=LEVEL'.
> > 
> >   This option is effective only when LEVEL is bigger than 0.
> >   Otherwise, it will be ignored with a warning.
> > 
> >   when LEVEL=1, warnings will be issued for a trailing array
> >   reference of a structure that have 2 or more elements if the
> >   trailing array is referenced as a flexible array member.
> > 
> >   when LEVEL=2, in addition to LEVEL=1, additional warnings will be
> >   issued for a trailing one-element array r

Re: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-15 Thread Qing Zhao via Gcc-patches


> On Dec 15, 2022, at 2:47 AM, Richard Biener  wrote:
> 
> On Wed, 14 Dec 2022, Qing Zhao wrote:
> 
>> Hi, Richard,
>> 
>> I guess that we now agreed on the following:
>> 
>> “ the information that we ran into a trailing array but didn't consider 
>> it a flex array because of -fstrict-flex-arrays is always a useful 
>> information”
>> 
>> The only thing we didn’t decide is:
>> 
>> A. Amend such new information to -Warray-bounds when -fstrict-flex-arrays=N 
>> (N>0) specified.
>> 
>> OR
>> 
>> B. Issue such new information with a new warning option -Wstrict-flex-arrays 
>> when -fstrict-flex-arrays=N (N>0) specified.
>> 
>> My current patch implemented B. 
> 
> Plus it implements it to specify a different flex-array variant for
> the extra diagnostic.
Could you clarify a little bit on this? (Don’t quite understand…)
> 
>> If you think A is better, I will change the patch as A. 
> 
> I would tend to A since, as I said, it's useful information that
> shouldn't be hidden and not adding an option removes odd combination
> possibilities such as -Wno-array-bounds -Wstrict-flex-arrays.

With current implementation, the above combination will ONLY report the misuse 
of trailing array as flex-array.  No out-of-bounds warnings issued.

> In particular I find, say, -fstrict-flex-arrays=2 -Wstrict-flex-arrays=1
> hardly useful.

The above combination will NOT happen, because there is NO level argument for 
-Wstrict-flex-arrays.

The only combination will be:-fstrict-flex-arrays=N -Wstrict-flex-arrays

When N > 0, -Wstrict-flex-arrays will report any misuse of trailing arrays as 
flexible array per the value of N.
> 
> But I'm interested in other opinions.

Adding a separate -Wstrict-flex-arrays will provide users a choice to ONLY look 
at the mis-use of trailing arrays as flex-arrays.  Without this new option, 
such information will be buried into tons of out-of-bounds messges. 

I think this is the major benefit to have one separate new warning 
-Wstrict-flex-arrays. 

Do we need to provide the users this choice?

Thanks.

Qing
> 
> Thanks,
> Richard.
> 
>> Let me know your opinion.
>> 
>> thanks.
>> 
>> Qing
>> 
>> 
>>> On Dec 14, 2022, at 4:03 AM, Richard Biener  wrote:
>>> 
>>> On Tue, 13 Dec 2022, Qing Zhao wrote:
>>> 
 Richard, 
 
 Do you have any decision on this one? 
 Do we need this warning option For GCC? 
>>> 
>>> Looking at the testcases it seems that the diagnostic amends
>>> -Warray-bounds diagnostics for trailing but not flexible arrays?
>>> Wouldn't it be better to generally diagnose this, so have
>>> -Warray-bounds, with -fstrict-flex-arrays, for
>>> 
>>> struct X { int a[1]; };
>>> int foo (struct X *p)
>>> {
>>> return p->a[1];
>>> }
>>> 
>>> emit
>>> 
>>> warning: array subscript 1 is above array bounds ...
>>> note: the trailing array is only a flexible array member with 
>>> -fno-strict-flex-arrays
>>> 
>>> ?  Having -Wstrict-flex-arrays=N and N not agree with the
>>> -fstrict-flex-arrays level sounds hardly useful to me but the
>>> information that we ran into a trailing array but didn't consider
>>> it a flex array because of -fstrict-flex-arrays is always a
>>> useful information?
>>> 
>>> But maybe I misunderstood this new diagnostic?
>>> 
>>> Thanks,
>>> Richard.
>>> 
>>> 
 thanks.
 
 Qing
 
> On Dec 6, 2022, at 11:18 AM, Qing Zhao  wrote:
> 
> '-Wstrict-flex-arrays'
>   Warn about inproper usages of flexible array members according to
>   the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
>   the trailing array field of a structure if it's available,
>   otherwise according to the LEVEL of the option
>   '-fstrict-flex-arrays=LEVEL'.
> 
>   This option is effective only when LEVEL is bigger than 0.
>   Otherwise, it will be ignored with a warning.
> 
>   when LEVEL=1, warnings will be issued for a trailing array
>   reference of a structure that have 2 or more elements if the
>   trailing array is referenced as a flexible array member.
> 
>   when LEVEL=2, in addition to LEVEL=1, additional warnings will be
>   issued for a trailing one-element array reference of a structure if
>   the array is referenced as a flexible array member.
> 
>   when LEVEL=3, in addition to LEVEL=2, additional warnings will be
>   issued for a trailing zero-length array reference of a structure if
>   the array is referenced as a flexible array member.
> 
> gcc/ChangeLog:
> 
>   * doc/invoke.texi: Document -Wstrict-flex-arrays option.
>   * gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two more
>   arguments.
>   (array_bounds_checker::check_array_ref): Issue warnings for
>   -Wstrict-flex-arrays.
>   * opts.cc (finish_options): Issue warning for unsupported combination
>   of -Wstrict_flex_arrays and -fstrict-flex-array.
>   * tree-vrp.cc (execute_ranger_vrp): Enable the pass when
>   warn_strict_flex_array 

Re: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-14 Thread Richard Biener via Gcc-patches
On Wed, 14 Dec 2022, Qing Zhao wrote:

> Hi, Richard,
> 
> I guess that we now agreed on the following:
> 
> “ the information that we ran into a trailing array but didn't consider 
> it a flex array because of -fstrict-flex-arrays is always a useful 
> information”
> 
> The only thing we didn’t decide is:
> 
> A. Amend such new information to -Warray-bounds when -fstrict-flex-arrays=N 
> (N>0) specified.
> 
> OR
> 
> B. Issue such new information with a new warning option -Wstrict-flex-arrays 
> when -fstrict-flex-arrays=N (N>0) specified.
> 
> My current patch implemented B. 

Plus it implements it to specify a different flex-array variant for
the extra diagnostic.

> If you think A is better, I will change the patch as A. 

I would tend to A since, as I said, it's useful information that
shouldn't be hidden and not adding an option removes odd combination
possibilities such as -Wno-array-bounds -Wstrict-flex-arrays.
In particular I find, say, -fstrict-flex-arrays=2 -Wstrict-flex-arrays=1
hardly useful.

But I'm interested in other opinions.

Thanks,
Richard.

> Let me know your opinion.
> 
> thanks.
> 
> Qing
> 
> 
> > On Dec 14, 2022, at 4:03 AM, Richard Biener  wrote:
> > 
> > On Tue, 13 Dec 2022, Qing Zhao wrote:
> > 
> >> Richard, 
> >> 
> >> Do you have any decision on this one? 
> >> Do we need this warning option For GCC? 
> > 
> > Looking at the testcases it seems that the diagnostic amends
> > -Warray-bounds diagnostics for trailing but not flexible arrays?
> > Wouldn't it be better to generally diagnose this, so have
> > -Warray-bounds, with -fstrict-flex-arrays, for
> > 
> > struct X { int a[1]; };
> > int foo (struct X *p)
> > {
> >  return p->a[1];
> > }
> > 
> > emit
> > 
> > warning: array subscript 1 is above array bounds ...
> > note: the trailing array is only a flexible array member with 
> > -fno-strict-flex-arrays
> > 
> > ?  Having -Wstrict-flex-arrays=N and N not agree with the
> > -fstrict-flex-arrays level sounds hardly useful to me but the
> > information that we ran into a trailing array but didn't consider
> > it a flex array because of -fstrict-flex-arrays is always a
> > useful information?
> > 
> > But maybe I misunderstood this new diagnostic?
> > 
> > Thanks,
> > Richard.
> > 
> > 
> >> thanks.
> >> 
> >> Qing
> >> 
> >>> On Dec 6, 2022, at 11:18 AM, Qing Zhao  wrote:
> >>> 
> >>> '-Wstrict-flex-arrays'
> >>>Warn about inproper usages of flexible array members according to
> >>>the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
> >>>the trailing array field of a structure if it's available,
> >>>otherwise according to the LEVEL of the option
> >>>'-fstrict-flex-arrays=LEVEL'.
> >>> 
> >>>This option is effective only when LEVEL is bigger than 0.
> >>>Otherwise, it will be ignored with a warning.
> >>> 
> >>>when LEVEL=1, warnings will be issued for a trailing array
> >>>reference of a structure that have 2 or more elements if the
> >>>trailing array is referenced as a flexible array member.
> >>> 
> >>>when LEVEL=2, in addition to LEVEL=1, additional warnings will be
> >>>issued for a trailing one-element array reference of a structure if
> >>>the array is referenced as a flexible array member.
> >>> 
> >>>when LEVEL=3, in addition to LEVEL=2, additional warnings will be
> >>>issued for a trailing zero-length array reference of a structure if
> >>>the array is referenced as a flexible array member.
> >>> 
> >>> gcc/ChangeLog:
> >>> 
> >>>   * doc/invoke.texi: Document -Wstrict-flex-arrays option.
> >>>   * gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two more
> >>>   arguments.
> >>>   (array_bounds_checker::check_array_ref): Issue warnings for
> >>>   -Wstrict-flex-arrays.
> >>>   * opts.cc (finish_options): Issue warning for unsupported combination
> >>>   of -Wstrict_flex_arrays and -fstrict-flex-array.
> >>>   * tree-vrp.cc (execute_ranger_vrp): Enable the pass when
> >>>   warn_strict_flex_array is true.
> >>> 
> >>> gcc/c-family/ChangeLog:
> >>> 
> >>>   * c.opt (Wstrict-flex-arrays): New option.
> >>> 
> >>> gcc/testsuite/ChangeLog:
> >>> 
> >>>   * gcc.dg/Warray-bounds-flex-arrays-1.c: Update testing case with
> >>>   -Wstrict-flex-arrays.
> >>>   * gcc.dg/Warray-bounds-flex-arrays-2.c: Likewise.
> >>>   * gcc.dg/Warray-bounds-flex-arrays-3.c: Likewise.
> >>>   * gcc.dg/Warray-bounds-flex-arrays-4.c: Likewise.
> >>>   * gcc.dg/Warray-bounds-flex-arrays-5.c: Likewise.
> >>>   * gcc.dg/Warray-bounds-flex-arrays-6.c: Likewise.
> >>>   * c-c++-common/Wstrict-flex-arrays.c: New test.
> >>>   * gcc.dg/Wstrict-flex-arrays-2.c: New test.
> >>>   * gcc.dg/Wstrict-flex-arrays-3.c: New test.
> >>>   * gcc.dg/Wstrict-flex-arrays.c: New test.
> >>> ---
> >>> gcc/c-family/c.opt|   5 +
> >>> gcc/doc/invoke.texi   |  27 -
> >>> gcc/gimple-array-bounds.cc| 103 ++
> >>> gcc/opts.cc 

Re: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-14 Thread Qing Zhao via Gcc-patches
Hi, Richard,

I guess that we now agreed on the following:

“ the information that we ran into a trailing array but didn't consider 
it a flex array because of -fstrict-flex-arrays is always a useful information”

The only thing we didn’t decide is:

A. Amend such new information to -Warray-bounds when -fstrict-flex-arrays=N 
(N>0) specified.

OR

B. Issue such new information with a new warning option -Wstrict-flex-arrays 
when -fstrict-flex-arrays=N (N>0) specified.

My current patch implemented B. 

If you think A is better, I will change the patch as A. 

Let me know your opinion.

thanks.

Qing


> On Dec 14, 2022, at 4:03 AM, Richard Biener  wrote:
> 
> On Tue, 13 Dec 2022, Qing Zhao wrote:
> 
>> Richard, 
>> 
>> Do you have any decision on this one? 
>> Do we need this warning option For GCC? 
> 
> Looking at the testcases it seems that the diagnostic amends
> -Warray-bounds diagnostics for trailing but not flexible arrays?
> Wouldn't it be better to generally diagnose this, so have
> -Warray-bounds, with -fstrict-flex-arrays, for
> 
> struct X { int a[1]; };
> int foo (struct X *p)
> {
>  return p->a[1];
> }
> 
> emit
> 
> warning: array subscript 1 is above array bounds ...
> note: the trailing array is only a flexible array member with 
> -fno-strict-flex-arrays
> 
> ?  Having -Wstrict-flex-arrays=N and N not agree with the
> -fstrict-flex-arrays level sounds hardly useful to me but the
> information that we ran into a trailing array but didn't consider
> it a flex array because of -fstrict-flex-arrays is always a
> useful information?
> 
> But maybe I misunderstood this new diagnostic?
> 
> Thanks,
> Richard.
> 
> 
>> thanks.
>> 
>> Qing
>> 
>>> On Dec 6, 2022, at 11:18 AM, Qing Zhao  wrote:
>>> 
>>> '-Wstrict-flex-arrays'
>>>Warn about inproper usages of flexible array members according to
>>>the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
>>>the trailing array field of a structure if it's available,
>>>otherwise according to the LEVEL of the option
>>>'-fstrict-flex-arrays=LEVEL'.
>>> 
>>>This option is effective only when LEVEL is bigger than 0.
>>>Otherwise, it will be ignored with a warning.
>>> 
>>>when LEVEL=1, warnings will be issued for a trailing array
>>>reference of a structure that have 2 or more elements if the
>>>trailing array is referenced as a flexible array member.
>>> 
>>>when LEVEL=2, in addition to LEVEL=1, additional warnings will be
>>>issued for a trailing one-element array reference of a structure if
>>>the array is referenced as a flexible array member.
>>> 
>>>when LEVEL=3, in addition to LEVEL=2, additional warnings will be
>>>issued for a trailing zero-length array reference of a structure if
>>>the array is referenced as a flexible array member.
>>> 
>>> gcc/ChangeLog:
>>> 
>>> * doc/invoke.texi: Document -Wstrict-flex-arrays option.
>>> * gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two more
>>> arguments.
>>> (array_bounds_checker::check_array_ref): Issue warnings for
>>> -Wstrict-flex-arrays.
>>> * opts.cc (finish_options): Issue warning for unsupported combination
>>> of -Wstrict_flex_arrays and -fstrict-flex-array.
>>> * tree-vrp.cc (execute_ranger_vrp): Enable the pass when
>>> warn_strict_flex_array is true.
>>> 
>>> gcc/c-family/ChangeLog:
>>> 
>>> * c.opt (Wstrict-flex-arrays): New option.
>>> 
>>> gcc/testsuite/ChangeLog:
>>> 
>>> * gcc.dg/Warray-bounds-flex-arrays-1.c: Update testing case with
>>> -Wstrict-flex-arrays.
>>> * gcc.dg/Warray-bounds-flex-arrays-2.c: Likewise.
>>> * gcc.dg/Warray-bounds-flex-arrays-3.c: Likewise.
>>> * gcc.dg/Warray-bounds-flex-arrays-4.c: Likewise.
>>> * gcc.dg/Warray-bounds-flex-arrays-5.c: Likewise.
>>> * gcc.dg/Warray-bounds-flex-arrays-6.c: Likewise.
>>> * c-c++-common/Wstrict-flex-arrays.c: New test.
>>> * gcc.dg/Wstrict-flex-arrays-2.c: New test.
>>> * gcc.dg/Wstrict-flex-arrays-3.c: New test.
>>> * gcc.dg/Wstrict-flex-arrays.c: New test.
>>> ---
>>> gcc/c-family/c.opt|   5 +
>>> gcc/doc/invoke.texi   |  27 -
>>> gcc/gimple-array-bounds.cc| 103 ++
>>> gcc/opts.cc   |   8 ++
>>> .../c-c++-common/Wstrict-flex-arrays.c|   9 ++
>>> .../gcc.dg/Warray-bounds-flex-arrays-1.c  |   5 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-2.c  |   6 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-3.c  |   7 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-4.c  |   5 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-5.c  |   6 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-6.c  |   7 +-
>>> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c  |  39 +++
>>> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c  |  39 +++
>>> gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c|  39 +++
>>> gcc/tree-vrp.cc   |  

Re: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-14 Thread Qing Zhao via Gcc-patches


> On Dec 14, 2022, at 9:08 AM, Qing Zhao via Gcc-patches 
>  wrote:
> 
> 
> 
>> On Dec 14, 2022, at 4:03 AM, Richard Biener  wrote:
>> 
>> On Tue, 13 Dec 2022, Qing Zhao wrote:
>> 
>>> Richard, 
>>> 
>>> Do you have any decision on this one? 
>>> Do we need this warning option For GCC? 
>> 
>> Looking at the testcases it seems that the diagnostic amends
>> -Warray-bounds diagnostics for trailing but not flexible arrays?
> 
> Yes.
> 
>> Wouldn't it be better to generally diagnose this, so have
>> -Warray-bounds, with -fstrict-flex-arrays, for
>> 
>> struct X { int a[1]; };
>> int foo (struct X *p)
>> {
>> return p->a[1];
>> }
>> 
>> emit
>> 
>> warning: array subscript 1 is above array bounds ...
>> note: the trailing array is only a flexible array member with 
>> -fno-strict-flex-arrays
> 
> This is good too.
> My only concern with doing this is, the default warning messages of 
> -Warray-bounds would be different than
> the current ones, will this have any impact on the current users?

My bad, the default warning message of -Warray-bounds without 
-fstrict-flex-arrays should not be changed.
Only when -fstrict-flex-arrays=N (N>0), the warning messages of -Warray-bounds 
will be different than the current one.
This should be fine.
> 
>> 
>> ?  Having -Wstrict-flex-arrays=N and N not agree with the
>> -fstrict-flex-arrays level sounds hardly useful to me but the
>> information that we ran into a trailing array but didn't consider
>> it a flex array because of -fstrict-flex-arrays is always a
>> useful information?
> 
> -Wstrict-flex-arrays does NOT have the argument “N”.  Its level will be 
> consistent with the level “N” of the corresponding
> -fstrict-flex-array=N.  
> -Wstrict-flex-arrays option is only valid when -fstrict-flex-arrays is 
> present, it will report any misuse of treating trailing array 
> as flexible array at the LEVEL of -fstrict-flex-arrays. 
> 
> Let me know if it is still not very clear.
> 
> thanks.
> 
> Qing
>> 
>> But maybe I misunderstood this new diagnostic?
>> 
>> Thanks,
>> Richard.
>> 
>> 
>>> thanks.
>>> 
>>> Qing
>>> 
 On Dec 6, 2022, at 11:18 AM, Qing Zhao  wrote:
 
 '-Wstrict-flex-arrays'
   Warn about inproper usages of flexible array members according to
   the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
   the trailing array field of a structure if it's available,
   otherwise according to the LEVEL of the option
   '-fstrict-flex-arrays=LEVEL'.
 
   This option is effective only when LEVEL is bigger than 0.
   Otherwise, it will be ignored with a warning.
 
   when LEVEL=1, warnings will be issued for a trailing array
   reference of a structure that have 2 or more elements if the
   trailing array is referenced as a flexible array member.
 
   when LEVEL=2, in addition to LEVEL=1, additional warnings will be
   issued for a trailing one-element array reference of a structure if
   the array is referenced as a flexible array member.
 
   when LEVEL=3, in addition to LEVEL=2, additional warnings will be
   issued for a trailing zero-length array reference of a structure if
   the array is referenced as a flexible array member.
 
 gcc/ChangeLog:
 
* doc/invoke.texi: Document -Wstrict-flex-arrays option.
* gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two more
arguments.
(array_bounds_checker::check_array_ref): Issue warnings for
-Wstrict-flex-arrays.
* opts.cc (finish_options): Issue warning for unsupported combination
of -Wstrict_flex_arrays and -fstrict-flex-array.
* tree-vrp.cc (execute_ranger_vrp): Enable the pass when
warn_strict_flex_array is true.
 
 gcc/c-family/ChangeLog:
 
* c.opt (Wstrict-flex-arrays): New option.
 
 gcc/testsuite/ChangeLog:
 
* gcc.dg/Warray-bounds-flex-arrays-1.c: Update testing case with
-Wstrict-flex-arrays.
* gcc.dg/Warray-bounds-flex-arrays-2.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-3.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-4.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-5.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-6.c: Likewise.
* c-c++-common/Wstrict-flex-arrays.c: New test.
* gcc.dg/Wstrict-flex-arrays-2.c: New test.
* gcc.dg/Wstrict-flex-arrays-3.c: New test.
* gcc.dg/Wstrict-flex-arrays.c: New test.
 ---
 gcc/c-family/c.opt|   5 +
 gcc/doc/invoke.texi   |  27 -
 gcc/gimple-array-bounds.cc| 103 ++
 gcc/opts.cc   |   8 ++
 .../c-c++-common/Wstrict-flex-arrays.c|   9 ++
 .../gcc.dg/Warray-bounds-flex-arrays-1.c  |   5 +-
 .../gcc.dg/Warray-bounds-flex-arrays-2.c  |   6 +-
 .../gcc.dg/Warray-bounds-flex-arrays-3.c  

Re: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-14 Thread Qing Zhao via Gcc-patches


> On Dec 14, 2022, at 4:03 AM, Richard Biener  wrote:
> 
> On Tue, 13 Dec 2022, Qing Zhao wrote:
> 
>> Richard, 
>> 
>> Do you have any decision on this one? 
>> Do we need this warning option For GCC? 
> 
> Looking at the testcases it seems that the diagnostic amends
> -Warray-bounds diagnostics for trailing but not flexible arrays?

Yes.

> Wouldn't it be better to generally diagnose this, so have
> -Warray-bounds, with -fstrict-flex-arrays, for
> 
> struct X { int a[1]; };
> int foo (struct X *p)
> {
>  return p->a[1];
> }
> 
> emit
> 
> warning: array subscript 1 is above array bounds ...
> note: the trailing array is only a flexible array member with 
> -fno-strict-flex-arrays

This is good too.
My only concern with doing this is, the default warning messages of 
-Warray-bounds would be different than
the current ones, will this have any impact on the current users?

> 
> ?  Having -Wstrict-flex-arrays=N and N not agree with the
> -fstrict-flex-arrays level sounds hardly useful to me but the
> information that we ran into a trailing array but didn't consider
> it a flex array because of -fstrict-flex-arrays is always a
> useful information?

-Wstrict-flex-arrays does NOT have the argument “N”.  Its level will be 
consistent with the level “N” of the corresponding
-fstrict-flex-array=N.  
-Wstrict-flex-arrays option is only valid when -fstrict-flex-arrays is present, 
it will report any misuse of treating trailing array 
as flexible array at the LEVEL of -fstrict-flex-arrays. 

Let me know if it is still not very clear.

thanks.

Qing
> 
> But maybe I misunderstood this new diagnostic?
> 
> Thanks,
> Richard.
> 
> 
>> thanks.
>> 
>> Qing
>> 
>>> On Dec 6, 2022, at 11:18 AM, Qing Zhao  wrote:
>>> 
>>> '-Wstrict-flex-arrays'
>>>Warn about inproper usages of flexible array members according to
>>>the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
>>>the trailing array field of a structure if it's available,
>>>otherwise according to the LEVEL of the option
>>>'-fstrict-flex-arrays=LEVEL'.
>>> 
>>>This option is effective only when LEVEL is bigger than 0.
>>>Otherwise, it will be ignored with a warning.
>>> 
>>>when LEVEL=1, warnings will be issued for a trailing array
>>>reference of a structure that have 2 or more elements if the
>>>trailing array is referenced as a flexible array member.
>>> 
>>>when LEVEL=2, in addition to LEVEL=1, additional warnings will be
>>>issued for a trailing one-element array reference of a structure if
>>>the array is referenced as a flexible array member.
>>> 
>>>when LEVEL=3, in addition to LEVEL=2, additional warnings will be
>>>issued for a trailing zero-length array reference of a structure if
>>>the array is referenced as a flexible array member.
>>> 
>>> gcc/ChangeLog:
>>> 
>>> * doc/invoke.texi: Document -Wstrict-flex-arrays option.
>>> * gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two more
>>> arguments.
>>> (array_bounds_checker::check_array_ref): Issue warnings for
>>> -Wstrict-flex-arrays.
>>> * opts.cc (finish_options): Issue warning for unsupported combination
>>> of -Wstrict_flex_arrays and -fstrict-flex-array.
>>> * tree-vrp.cc (execute_ranger_vrp): Enable the pass when
>>> warn_strict_flex_array is true.
>>> 
>>> gcc/c-family/ChangeLog:
>>> 
>>> * c.opt (Wstrict-flex-arrays): New option.
>>> 
>>> gcc/testsuite/ChangeLog:
>>> 
>>> * gcc.dg/Warray-bounds-flex-arrays-1.c: Update testing case with
>>> -Wstrict-flex-arrays.
>>> * gcc.dg/Warray-bounds-flex-arrays-2.c: Likewise.
>>> * gcc.dg/Warray-bounds-flex-arrays-3.c: Likewise.
>>> * gcc.dg/Warray-bounds-flex-arrays-4.c: Likewise.
>>> * gcc.dg/Warray-bounds-flex-arrays-5.c: Likewise.
>>> * gcc.dg/Warray-bounds-flex-arrays-6.c: Likewise.
>>> * c-c++-common/Wstrict-flex-arrays.c: New test.
>>> * gcc.dg/Wstrict-flex-arrays-2.c: New test.
>>> * gcc.dg/Wstrict-flex-arrays-3.c: New test.
>>> * gcc.dg/Wstrict-flex-arrays.c: New test.
>>> ---
>>> gcc/c-family/c.opt|   5 +
>>> gcc/doc/invoke.texi   |  27 -
>>> gcc/gimple-array-bounds.cc| 103 ++
>>> gcc/opts.cc   |   8 ++
>>> .../c-c++-common/Wstrict-flex-arrays.c|   9 ++
>>> .../gcc.dg/Warray-bounds-flex-arrays-1.c  |   5 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-2.c  |   6 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-3.c  |   7 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-4.c  |   5 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-5.c  |   6 +-
>>> .../gcc.dg/Warray-bounds-flex-arrays-6.c  |   7 +-
>>> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c  |  39 +++
>>> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c  |  39 +++
>>> gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c|  39 +++
>>> gcc/tree-vrp.cc   |   2 +-

Re: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-14 Thread Richard Biener via Gcc-patches
On Tue, 13 Dec 2022, Qing Zhao wrote:

> Richard, 
> 
> Do you have any decision on this one? 
> Do we need this warning option For GCC? 

Looking at the testcases it seems that the diagnostic amends
-Warray-bounds diagnostics for trailing but not flexible arrays?
Wouldn't it be better to generally diagnose this, so have
-Warray-bounds, with -fstrict-flex-arrays, for

struct X { int a[1]; };
int foo (struct X *p)
{
  return p->a[1];
}

emit

warning: array subscript 1 is above array bounds ...
note: the trailing array is only a flexible array member with 
-fno-strict-flex-arrays

?  Having -Wstrict-flex-arrays=N and N not agree with the
-fstrict-flex-arrays level sounds hardly useful to me but the
information that we ran into a trailing array but didn't consider
it a flex array because of -fstrict-flex-arrays is always a
useful information?

But maybe I misunderstood this new diagnostic?

Thanks,
Richard.


> thanks.
> 
> Qing
> 
> > On Dec 6, 2022, at 11:18 AM, Qing Zhao  wrote:
> > 
> > '-Wstrict-flex-arrays'
> > Warn about inproper usages of flexible array members according to
> > the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
> > the trailing array field of a structure if it's available,
> > otherwise according to the LEVEL of the option
> > '-fstrict-flex-arrays=LEVEL'.
> > 
> > This option is effective only when LEVEL is bigger than 0.
> > Otherwise, it will be ignored with a warning.
> > 
> > when LEVEL=1, warnings will be issued for a trailing array
> > reference of a structure that have 2 or more elements if the
> > trailing array is referenced as a flexible array member.
> > 
> > when LEVEL=2, in addition to LEVEL=1, additional warnings will be
> > issued for a trailing one-element array reference of a structure if
> > the array is referenced as a flexible array member.
> > 
> > when LEVEL=3, in addition to LEVEL=2, additional warnings will be
> > issued for a trailing zero-length array reference of a structure if
> > the array is referenced as a flexible array member.
> > 
> > gcc/ChangeLog:
> > 
> > * doc/invoke.texi: Document -Wstrict-flex-arrays option.
> > * gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two more
> > arguments.
> > (array_bounds_checker::check_array_ref): Issue warnings for
> > -Wstrict-flex-arrays.
> > * opts.cc (finish_options): Issue warning for unsupported combination
> > of -Wstrict_flex_arrays and -fstrict-flex-array.
> > * tree-vrp.cc (execute_ranger_vrp): Enable the pass when
> > warn_strict_flex_array is true.
> > 
> > gcc/c-family/ChangeLog:
> > 
> > * c.opt (Wstrict-flex-arrays): New option.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > * gcc.dg/Warray-bounds-flex-arrays-1.c: Update testing case with
> > -Wstrict-flex-arrays.
> > * gcc.dg/Warray-bounds-flex-arrays-2.c: Likewise.
> > * gcc.dg/Warray-bounds-flex-arrays-3.c: Likewise.
> > * gcc.dg/Warray-bounds-flex-arrays-4.c: Likewise.
> > * gcc.dg/Warray-bounds-flex-arrays-5.c: Likewise.
> > * gcc.dg/Warray-bounds-flex-arrays-6.c: Likewise.
> > * c-c++-common/Wstrict-flex-arrays.c: New test.
> > * gcc.dg/Wstrict-flex-arrays-2.c: New test.
> > * gcc.dg/Wstrict-flex-arrays-3.c: New test.
> > * gcc.dg/Wstrict-flex-arrays.c: New test.
> > ---
> > gcc/c-family/c.opt|   5 +
> > gcc/doc/invoke.texi   |  27 -
> > gcc/gimple-array-bounds.cc| 103 ++
> > gcc/opts.cc   |   8 ++
> > .../c-c++-common/Wstrict-flex-arrays.c|   9 ++
> > .../gcc.dg/Warray-bounds-flex-arrays-1.c  |   5 +-
> > .../gcc.dg/Warray-bounds-flex-arrays-2.c  |   6 +-
> > .../gcc.dg/Warray-bounds-flex-arrays-3.c  |   7 +-
> > .../gcc.dg/Warray-bounds-flex-arrays-4.c  |   5 +-
> > .../gcc.dg/Warray-bounds-flex-arrays-5.c  |   6 +-
> > .../gcc.dg/Warray-bounds-flex-arrays-6.c  |   7 +-
> > gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c  |  39 +++
> > gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c  |  39 +++
> > gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c|  39 +++
> > gcc/tree-vrp.cc   |   2 +-
> > 15 files changed, 273 insertions(+), 34 deletions(-)
> > create mode 100644 gcc/testsuite/c-c++-common/Wstrict-flex-arrays.c
> > create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c
> > create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c
> > create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c
> > 
> > diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> > index 0d0ad0a6374..33edeefd285 100644
> > --- a/gcc/c-family/c.opt
> > +++ b/gcc/c-family/c.opt
> > @@ -976,6 +976,11 @@ Wstringop-truncation
> > C ObjC C++ LTO ObjC++ Var(warn_stringop_truncation) Warning Init (1) 
> > LangEnabledBy(C ObjC C++ LTO ObjC++, Wall)
> > Warn about truncation in string manipulation functi

Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-13 Thread Qing Zhao via Gcc-patches
Richard, 

Do you have any decision on this one? 
Do we need this warning option For GCC? 

thanks.

Qing

> On Dec 6, 2022, at 11:18 AM, Qing Zhao  wrote:
> 
> '-Wstrict-flex-arrays'
> Warn about inproper usages of flexible array members according to
> the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
> the trailing array field of a structure if it's available,
> otherwise according to the LEVEL of the option
> '-fstrict-flex-arrays=LEVEL'.
> 
> This option is effective only when LEVEL is bigger than 0.
> Otherwise, it will be ignored with a warning.
> 
> when LEVEL=1, warnings will be issued for a trailing array
> reference of a structure that have 2 or more elements if the
> trailing array is referenced as a flexible array member.
> 
> when LEVEL=2, in addition to LEVEL=1, additional warnings will be
> issued for a trailing one-element array reference of a structure if
> the array is referenced as a flexible array member.
> 
> when LEVEL=3, in addition to LEVEL=2, additional warnings will be
> issued for a trailing zero-length array reference of a structure if
> the array is referenced as a flexible array member.
> 
> gcc/ChangeLog:
> 
>   * doc/invoke.texi: Document -Wstrict-flex-arrays option.
>   * gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two more
>   arguments.
>   (array_bounds_checker::check_array_ref): Issue warnings for
>   -Wstrict-flex-arrays.
>   * opts.cc (finish_options): Issue warning for unsupported combination
>   of -Wstrict_flex_arrays and -fstrict-flex-array.
>   * tree-vrp.cc (execute_ranger_vrp): Enable the pass when
>   warn_strict_flex_array is true.
> 
> gcc/c-family/ChangeLog:
> 
>   * c.opt (Wstrict-flex-arrays): New option.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gcc.dg/Warray-bounds-flex-arrays-1.c: Update testing case with
>   -Wstrict-flex-arrays.
>   * gcc.dg/Warray-bounds-flex-arrays-2.c: Likewise.
>   * gcc.dg/Warray-bounds-flex-arrays-3.c: Likewise.
>   * gcc.dg/Warray-bounds-flex-arrays-4.c: Likewise.
>   * gcc.dg/Warray-bounds-flex-arrays-5.c: Likewise.
>   * gcc.dg/Warray-bounds-flex-arrays-6.c: Likewise.
>   * c-c++-common/Wstrict-flex-arrays.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-2.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-3.c: New test.
>   * gcc.dg/Wstrict-flex-arrays.c: New test.
> ---
> gcc/c-family/c.opt|   5 +
> gcc/doc/invoke.texi   |  27 -
> gcc/gimple-array-bounds.cc| 103 ++
> gcc/opts.cc   |   8 ++
> .../c-c++-common/Wstrict-flex-arrays.c|   9 ++
> .../gcc.dg/Warray-bounds-flex-arrays-1.c  |   5 +-
> .../gcc.dg/Warray-bounds-flex-arrays-2.c  |   6 +-
> .../gcc.dg/Warray-bounds-flex-arrays-3.c  |   7 +-
> .../gcc.dg/Warray-bounds-flex-arrays-4.c  |   5 +-
> .../gcc.dg/Warray-bounds-flex-arrays-5.c  |   6 +-
> .../gcc.dg/Warray-bounds-flex-arrays-6.c  |   7 +-
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c  |  39 +++
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c  |  39 +++
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c|  39 +++
> gcc/tree-vrp.cc   |   2 +-
> 15 files changed, 273 insertions(+), 34 deletions(-)
> create mode 100644 gcc/testsuite/c-c++-common/Wstrict-flex-arrays.c
> create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c
> create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c
> create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c
> 
> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> index 0d0ad0a6374..33edeefd285 100644
> --- a/gcc/c-family/c.opt
> +++ b/gcc/c-family/c.opt
> @@ -976,6 +976,11 @@ Wstringop-truncation
> C ObjC C++ LTO ObjC++ Var(warn_stringop_truncation) Warning Init (1) 
> LangEnabledBy(C ObjC C++ LTO ObjC++, Wall)
> Warn about truncation in string manipulation functions like strncat and 
> strncpy.
> 
> +Wstrict-flex-arrays
> +C C++ Var(warn_strict_flex_arrays) Warning
> +Warn about inproper usages of flexible array members
> +according to the level of -fstrict-flex-arrays.
> +
> Wsuggest-attribute=format
> C ObjC C++ ObjC++ Var(warn_suggest_attribute_format) Warning
> Warn about functions which might be candidates for format attributes.
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 726392409b6..4402b0427ef 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -398,7 +398,7 @@ Objective-C and Objective-C++ Dialects}.
> -Wstrict-aliasing=n  -Wstrict-overflow  -Wstrict-overflow=@var{n} @gol
> -Wstring-compare @gol
> -Wno-stringop-overflow -Wno-stringop-overread @gol
> --Wno-stringop-truncation @gol
> +-Wno-stringop-truncation -Wstrict-flex-arrays @gol
> -Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{|}malloc@r{]}
>  @gol
> -Wswitch  -Wno-switch-bool  -Wswitch-

[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-12-06 Thread Qing Zhao via Gcc-patches
'-Wstrict-flex-arrays'
 Warn about inproper usages of flexible array members according to
 the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
 the trailing array field of a structure if it's available,
 otherwise according to the LEVEL of the option
 '-fstrict-flex-arrays=LEVEL'.

 This option is effective only when LEVEL is bigger than 0.
 Otherwise, it will be ignored with a warning.

 when LEVEL=1, warnings will be issued for a trailing array
 reference of a structure that have 2 or more elements if the
 trailing array is referenced as a flexible array member.

 when LEVEL=2, in addition to LEVEL=1, additional warnings will be
 issued for a trailing one-element array reference of a structure if
 the array is referenced as a flexible array member.

 when LEVEL=3, in addition to LEVEL=2, additional warnings will be
 issued for a trailing zero-length array reference of a structure if
 the array is referenced as a flexible array member.

gcc/ChangeLog:

* doc/invoke.texi: Document -Wstrict-flex-arrays option.
* gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two more
arguments.
(array_bounds_checker::check_array_ref): Issue warnings for
-Wstrict-flex-arrays.
* opts.cc (finish_options): Issue warning for unsupported combination
of -Wstrict_flex_arrays and -fstrict-flex-array.
* tree-vrp.cc (execute_ranger_vrp): Enable the pass when
warn_strict_flex_array is true.

gcc/c-family/ChangeLog:

* c.opt (Wstrict-flex-arrays): New option.

gcc/testsuite/ChangeLog:

* gcc.dg/Warray-bounds-flex-arrays-1.c: Update testing case with
-Wstrict-flex-arrays.
* gcc.dg/Warray-bounds-flex-arrays-2.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-3.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-4.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-5.c: Likewise.
* gcc.dg/Warray-bounds-flex-arrays-6.c: Likewise.
* c-c++-common/Wstrict-flex-arrays.c: New test.
* gcc.dg/Wstrict-flex-arrays-2.c: New test.
* gcc.dg/Wstrict-flex-arrays-3.c: New test.
* gcc.dg/Wstrict-flex-arrays.c: New test.
---
 gcc/c-family/c.opt|   5 +
 gcc/doc/invoke.texi   |  27 -
 gcc/gimple-array-bounds.cc| 103 ++
 gcc/opts.cc   |   8 ++
 .../c-c++-common/Wstrict-flex-arrays.c|   9 ++
 .../gcc.dg/Warray-bounds-flex-arrays-1.c  |   5 +-
 .../gcc.dg/Warray-bounds-flex-arrays-2.c  |   6 +-
 .../gcc.dg/Warray-bounds-flex-arrays-3.c  |   7 +-
 .../gcc.dg/Warray-bounds-flex-arrays-4.c  |   5 +-
 .../gcc.dg/Warray-bounds-flex-arrays-5.c  |   6 +-
 .../gcc.dg/Warray-bounds-flex-arrays-6.c  |   7 +-
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c  |  39 +++
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c  |  39 +++
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c|  39 +++
 gcc/tree-vrp.cc   |   2 +-
 15 files changed, 273 insertions(+), 34 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/Wstrict-flex-arrays.c
 create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c
 create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c
 create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 0d0ad0a6374..33edeefd285 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -976,6 +976,11 @@ Wstringop-truncation
 C ObjC C++ LTO ObjC++ Var(warn_stringop_truncation) Warning Init (1) 
LangEnabledBy(C ObjC C++ LTO ObjC++, Wall)
 Warn about truncation in string manipulation functions like strncat and 
strncpy.
 
+Wstrict-flex-arrays
+C C++ Var(warn_strict_flex_arrays) Warning
+Warn about inproper usages of flexible array members
+according to the level of -fstrict-flex-arrays.
+
 Wsuggest-attribute=format
 C ObjC C++ ObjC++ Var(warn_suggest_attribute_format) Warning
 Warn about functions which might be candidates for format attributes.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 726392409b6..4402b0427ef 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -398,7 +398,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wstrict-aliasing=n  -Wstrict-overflow  -Wstrict-overflow=@var{n} @gol
 -Wstring-compare @gol
 -Wno-stringop-overflow -Wno-stringop-overread @gol
--Wno-stringop-truncation @gol
+-Wno-stringop-truncation -Wstrict-flex-arrays @gol
 
-Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{|}malloc@r{]} 
@gol
 -Wswitch  -Wno-switch-bool  -Wswitch-default  -Wswitch-enum @gol
 -Wno-switch-outside-range  -Wno-switch-unreachable  -Wsync-nand @gol
@@ -7835,6 +7835,31 @@ however, are not suitable arguments to functions that 
expect
 such arrays GCC issues warnings unless it can prove that the use is
 safe.  @xref{Common Vari

Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-23 Thread Richard Biener via Gcc-patches
On Tue, 22 Nov 2022, Kees Cook wrote:

> On Tue, Nov 22, 2022 at 03:02:04PM +, Qing Zhao wrote:
> > 
> > 
> > > On Nov 22, 2022, at 9:10 AM, Qing Zhao via Gcc-patches 
> > >  wrote:
> > > 
> > > 
> > > 
> > >> On Nov 22, 2022, at 3:16 AM, Richard Biener  wrote:
> > >> 
> > >> On Mon, 21 Nov 2022, Qing Zhao wrote:
> > >> 
> > >>> 
> > >>> 
> >  On Nov 18, 2022, at 11:31 AM, Kees Cook  wrote:
> >  
> >  On Fri, Nov 18, 2022 at 03:19:07PM +, Qing Zhao wrote:
> > > Hi, Richard,
> > > 
> > > Honestly, it?s very hard for me to decide what?s the best way to 
> > > handle the interaction 
> > > between -fstrict-flex-array=M and -Warray-bounds=N. 
> > > 
> > > Ideally,  -fstrict-flex-array=M should completely control the 
> > > behavior of -Warray-bounds.
> > > If possible, I prefer this solution.
> > > 
> > > However, -Warray-bounds is included in -Wall, and has been used 
> > > extensively for a long time.
> > > It?s not safe to change its default behavior. 
> >  
> >  I prefer that -fstrict-flex-arrays controls -Warray-bounds. That
> >  it is in -Wall is _good_ for this reason. :) No one is going to add
> >  -fstrict-flex-arrays (at any level) without understanding what it does
> >  and wanting those effects on -Warray-bounds.
> > >>> 
> > >>> 
> > >>> The major difficulties to let -fstrict-flex-arrays controlling 
> > >>> -Warray-bounds was discussed in the following threads:
> > >>> 
> > >>> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604133.html
> > >>> 
> > >>> Please take a look at the discussion and let me know your opinion.
> > >> 
> > >> My opinion is now, after re-considering and with seeing your new 
> > >> patch, that -Warray-bounds=2 should be changed to only add
> > >> "the intermediate results of pointer arithmetic that may yield out of 
> > >> bounds values" and that what it considers a flex array should now
> > >> be controlled by -fstrict-flex-arrays only.
> > >> 
> > >> That is, I think, the only thing that's not confusing to users even
> > >> if that implies a change from previous behavior that we should
> > >> document by clarifying the -Warray-bounds documentation as well as
> > >> by adding an entry to the Caveats section of gcc-13/changes.html
> > >> 
> > >> That also means that =2 will get _less_ warnings with GCC 13 when
> > >> the user doesn't use -fstrict-flex-arrays as well.
> > > 
> > > Okay.  So, this is for -Warray-bounds=2.
> > > 
> > > For -Warray-bounds=1 -fstrict-flex-array=N, if N > 1, should 
> > > -fstrict-flex-array=N control -Warray-bounds=1?
> > 
> > More thinking on this. (I might misunderstand a little bit in the previous 
> > email)
> > 
> > If I understand correctly now, what you proposed was:
> > 
> > 1. The level of -Warray-bounds will NOT control how a trailing array is 
> > considered as a flex array member anymore. 
> > 2. Only the level of -fstrict-flex-arrays will control this;
> > 3. Keep the current default  behavior of -Warray-bounds on treating 
> > trailing arrays as flex array member (treating all [0],[1], and [] as 
> > flexible array members). 
> > 4. Updating the documentation for -Warray-bounds by clarifying this change, 
> > and also as an entry to the Caveats section on such change on 
> > -Warray-bounds.
> > 
> > If the above is correct, Yes, I like this change. Both the user interface 
> > and the internal implementation will be simplified and cleaner. 
> > 
> > Let me know if you see any issue with my above understanding.
> > 
> > Thanks a lot.
> 
> FWIW, this matches what I think makes the most sense too.

Yes, I think that makes most sense.  As said for -Warray-bounds=2 this
will change behavior but since that's not the default that should be
fine if documented.

Thanks,
Richard.


Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-22 Thread Kees Cook via Gcc-patches
On Tue, Nov 22, 2022 at 03:02:04PM +, Qing Zhao wrote:
> 
> 
> > On Nov 22, 2022, at 9:10 AM, Qing Zhao via Gcc-patches 
> >  wrote:
> > 
> > 
> > 
> >> On Nov 22, 2022, at 3:16 AM, Richard Biener  wrote:
> >> 
> >> On Mon, 21 Nov 2022, Qing Zhao wrote:
> >> 
> >>> 
> >>> 
>  On Nov 18, 2022, at 11:31 AM, Kees Cook  wrote:
>  
>  On Fri, Nov 18, 2022 at 03:19:07PM +, Qing Zhao wrote:
> > Hi, Richard,
> > 
> > Honestly, it?s very hard for me to decide what?s the best way to handle 
> > the interaction 
> > between -fstrict-flex-array=M and -Warray-bounds=N. 
> > 
> > Ideally,  -fstrict-flex-array=M should completely control the behavior 
> > of -Warray-bounds.
> > If possible, I prefer this solution.
> > 
> > However, -Warray-bounds is included in -Wall, and has been used 
> > extensively for a long time.
> > It?s not safe to change its default behavior. 
>  
>  I prefer that -fstrict-flex-arrays controls -Warray-bounds. That
>  it is in -Wall is _good_ for this reason. :) No one is going to add
>  -fstrict-flex-arrays (at any level) without understanding what it does
>  and wanting those effects on -Warray-bounds.
> >>> 
> >>> 
> >>> The major difficulties to let -fstrict-flex-arrays controlling 
> >>> -Warray-bounds was discussed in the following threads:
> >>> 
> >>> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604133.html
> >>> 
> >>> Please take a look at the discussion and let me know your opinion.
> >> 
> >> My opinion is now, after re-considering and with seeing your new 
> >> patch, that -Warray-bounds=2 should be changed to only add
> >> "the intermediate results of pointer arithmetic that may yield out of 
> >> bounds values" and that what it considers a flex array should now
> >> be controlled by -fstrict-flex-arrays only.
> >> 
> >> That is, I think, the only thing that's not confusing to users even
> >> if that implies a change from previous behavior that we should
> >> document by clarifying the -Warray-bounds documentation as well as
> >> by adding an entry to the Caveats section of gcc-13/changes.html
> >> 
> >> That also means that =2 will get _less_ warnings with GCC 13 when
> >> the user doesn't use -fstrict-flex-arrays as well.
> > 
> > Okay.  So, this is for -Warray-bounds=2.
> > 
> > For -Warray-bounds=1 -fstrict-flex-array=N, if N > 1, should 
> > -fstrict-flex-array=N control -Warray-bounds=1?
> 
> More thinking on this. (I might misunderstand a little bit in the previous 
> email)
> 
> If I understand correctly now, what you proposed was:
> 
> 1. The level of -Warray-bounds will NOT control how a trailing array is 
> considered as a flex array member anymore. 
> 2. Only the level of -fstrict-flex-arrays will control this;
> 3. Keep the current default  behavior of -Warray-bounds on treating trailing 
> arrays as flex array member (treating all [0],[1], and [] as flexible array 
> members). 
> 4. Updating the documentation for -Warray-bounds by clarifying this change, 
> and also as an entry to the Caveats section on such change on -Warray-bounds.
> 
> If the above is correct, Yes, I like this change. Both the user interface and 
> the internal implementation will be simplified and cleaner. 
> 
> Let me know if you see any issue with my above understanding.
> 
> Thanks a lot.

FWIW, this matches what I think makes the most sense too.

-- 
Kees Cook


Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-22 Thread Qing Zhao via Gcc-patches



> On Nov 22, 2022, at 9:10 AM, Qing Zhao via Gcc-patches 
>  wrote:
> 
> 
> 
>> On Nov 22, 2022, at 3:16 AM, Richard Biener  wrote:
>> 
>> On Mon, 21 Nov 2022, Qing Zhao wrote:
>> 
>>> 
>>> 
 On Nov 18, 2022, at 11:31 AM, Kees Cook  wrote:
 
 On Fri, Nov 18, 2022 at 03:19:07PM +, Qing Zhao wrote:
> Hi, Richard,
> 
> Honestly, it?s very hard for me to decide what?s the best way to handle 
> the interaction 
> between -fstrict-flex-array=M and -Warray-bounds=N. 
> 
> Ideally,  -fstrict-flex-array=M should completely control the behavior of 
> -Warray-bounds.
> If possible, I prefer this solution.
> 
> However, -Warray-bounds is included in -Wall, and has been used 
> extensively for a long time.
> It?s not safe to change its default behavior. 
 
 I prefer that -fstrict-flex-arrays controls -Warray-bounds. That
 it is in -Wall is _good_ for this reason. :) No one is going to add
 -fstrict-flex-arrays (at any level) without understanding what it does
 and wanting those effects on -Warray-bounds.
>>> 
>>> 
>>> The major difficulties to let -fstrict-flex-arrays controlling 
>>> -Warray-bounds was discussed in the following threads:
>>> 
>>> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604133.html
>>> 
>>> Please take a look at the discussion and let me know your opinion.
>> 
>> My opinion is now, after re-considering and with seeing your new 
>> patch, that -Warray-bounds=2 should be changed to only add
>> "the intermediate results of pointer arithmetic that may yield out of 
>> bounds values" and that what it considers a flex array should now
>> be controlled by -fstrict-flex-arrays only.
>> 
>> That is, I think, the only thing that's not confusing to users even
>> if that implies a change from previous behavior that we should
>> document by clarifying the -Warray-bounds documentation as well as
>> by adding an entry to the Caveats section of gcc-13/changes.html
>> 
>> That also means that =2 will get _less_ warnings with GCC 13 when
>> the user doesn't use -fstrict-flex-arrays as well.
> 
> Okay.  So, this is for -Warray-bounds=2.
> 
> For -Warray-bounds=1 -fstrict-flex-array=N, if N > 1, should 
> -fstrict-flex-array=N control -Warray-bounds=1?

More thinking on this. (I might misunderstand a little bit in the previous 
email)

If I understand correctly now, what you proposed was:

1. The level of -Warray-bounds will NOT control how a trailing array is 
considered as a flex array member anymore. 
2. Only the level of -fstrict-flex-arrays will control this;
3. Keep the current default  behavior of -Warray-bounds on treating trailing 
arrays as flex array member (treating all [0],[1], and [] as flexible array 
members). 
4. Updating the documentation for -Warray-bounds by clarifying this change, and 
also as an entry to the Caveats section on such change on -Warray-bounds.

If the above is correct, Yes, I like this change. Both the user interface and 
the internal implementation will be simplified and cleaner. 

Let me know if you see any issue with my above understanding.

Thanks a lot.

Qing

> 
> Qing
> 
>> 
>> Richard.
>> 
>> -- 
>> Richard Biener 
>> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
>> Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
>> HRB 36809 (AG Nuernberg)



Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-22 Thread Qing Zhao via Gcc-patches



> On Nov 22, 2022, at 3:16 AM, Richard Biener  wrote:
> 
> On Mon, 21 Nov 2022, Qing Zhao wrote:
> 
>> 
>> 
>>> On Nov 18, 2022, at 11:31 AM, Kees Cook  wrote:
>>> 
>>> On Fri, Nov 18, 2022 at 03:19:07PM +, Qing Zhao wrote:
 Hi, Richard,
 
 Honestly, it?s very hard for me to decide what?s the best way to handle 
 the interaction 
 between -fstrict-flex-array=M and -Warray-bounds=N. 
 
 Ideally,  -fstrict-flex-array=M should completely control the behavior of 
 -Warray-bounds.
 If possible, I prefer this solution.
 
 However, -Warray-bounds is included in -Wall, and has been used 
 extensively for a long time.
 It?s not safe to change its default behavior. 
>>> 
>>> I prefer that -fstrict-flex-arrays controls -Warray-bounds. That
>>> it is in -Wall is _good_ for this reason. :) No one is going to add
>>> -fstrict-flex-arrays (at any level) without understanding what it does
>>> and wanting those effects on -Warray-bounds.
>> 
>> 
>> The major difficulties to let -fstrict-flex-arrays controlling 
>> -Warray-bounds was discussed in the following threads:
>> 
>> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604133.html
>> 
>> Please take a look at the discussion and let me know your opinion.
> 
> My opinion is now, after re-considering and with seeing your new 
> patch, that -Warray-bounds=2 should be changed to only add
> "the intermediate results of pointer arithmetic that may yield out of 
> bounds values" and that what it considers a flex array should now
> be controlled by -fstrict-flex-arrays only.
> 
> That is, I think, the only thing that's not confusing to users even
> if that implies a change from previous behavior that we should
> document by clarifying the -Warray-bounds documentation as well as
> by adding an entry to the Caveats section of gcc-13/changes.html
> 
> That also means that =2 will get _less_ warnings with GCC 13 when
> the user doesn't use -fstrict-flex-arrays as well.

Okay.  So, this is for -Warray-bounds=2.

For -Warray-bounds=1 -fstrict-flex-array=N, if N > 1, should 
-fstrict-flex-array=N control -Warray-bounds=1?

Qing

> 
> Richard.
> 
> -- 
> Richard Biener 
> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
> Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
> HRB 36809 (AG Nuernberg)



Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-22 Thread Richard Biener via Gcc-patches
On Mon, 21 Nov 2022, Qing Zhao wrote:

> 
> 
> > On Nov 18, 2022, at 11:31 AM, Kees Cook  wrote:
> > 
> > On Fri, Nov 18, 2022 at 03:19:07PM +, Qing Zhao wrote:
> >> Hi, Richard,
> >> 
> >> Honestly, it?s very hard for me to decide what?s the best way to handle 
> >> the interaction 
> >> between -fstrict-flex-array=M and -Warray-bounds=N. 
> >> 
> >> Ideally,  -fstrict-flex-array=M should completely control the behavior of 
> >> -Warray-bounds.
> >> If possible, I prefer this solution.
> >> 
> >> However, -Warray-bounds is included in -Wall, and has been used 
> >> extensively for a long time.
> >> It?s not safe to change its default behavior. 
> > 
> > I prefer that -fstrict-flex-arrays controls -Warray-bounds. That
> > it is in -Wall is _good_ for this reason. :) No one is going to add
> > -fstrict-flex-arrays (at any level) without understanding what it does
> > and wanting those effects on -Warray-bounds.
> 
> 
> The major difficulties to let -fstrict-flex-arrays controlling -Warray-bounds 
> was discussed in the following threads:
> 
> https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604133.html
> 
> Please take a look at the discussion and let me know your opinion.

My opinion is now, after re-considering and with seeing your new 
patch, that -Warray-bounds=2 should be changed to only add
"the intermediate results of pointer arithmetic that may yield out of 
bounds values" and that what it considers a flex array should now
be controlled by -fstrict-flex-arrays only.

That is, I think, the only thing that's not confusing to users even
if that implies a change from previous behavior that we should
document by clarifying the -Warray-bounds documentation as well as
by adding an entry to the Caveats section of gcc-13/changes.html

That also means that =2 will get _less_ warnings with GCC 13 when
the user doesn't use -fstrict-flex-arrays as well.

Richard.

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)


Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-21 Thread Qing Zhao via Gcc-patches


> On Nov 18, 2022, at 11:31 AM, Kees Cook  wrote:
> 
> On Fri, Nov 18, 2022 at 03:19:07PM +, Qing Zhao wrote:
>> Hi, Richard,
>> 
>> Honestly, it’s very hard for me to decide what’s the best way to handle the 
>> interaction 
>> between -fstrict-flex-array=M and -Warray-bounds=N. 
>> 
>> Ideally,  -fstrict-flex-array=M should completely control the behavior of 
>> -Warray-bounds.
>> If possible, I prefer this solution.
>> 
>> However, -Warray-bounds is included in -Wall, and has been used extensively 
>> for a long time.
>> It’s not safe to change its default behavior. 
> 
> I prefer that -fstrict-flex-arrays controls -Warray-bounds. That
> it is in -Wall is _good_ for this reason. :) No one is going to add
> -fstrict-flex-arrays (at any level) without understanding what it does
> and wanting those effects on -Warray-bounds.


The major difficulties to let -fstrict-flex-arrays controlling -Warray-bounds 
was discussed in the following threads:

https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604133.html

Please take a look at the discussion and let me know your opinion.

Thanks,

Qing

> 
> -- 
> Kees Cook



Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-18 Thread Kees Cook via Gcc-patches
On Fri, Nov 18, 2022 at 03:19:07PM +, Qing Zhao wrote:
> Hi, Richard,
> 
> Honestly, it’s very hard for me to decide what’s the best way to handle the 
> interaction 
> between -fstrict-flex-array=M and -Warray-bounds=N. 
> 
> Ideally,  -fstrict-flex-array=M should completely control the behavior of 
> -Warray-bounds.
> If possible, I prefer this solution.
> 
> However, -Warray-bounds is included in -Wall, and has been used extensively 
> for a long time.
> It’s not safe to change its default behavior. 

I prefer that -fstrict-flex-arrays controls -Warray-bounds. That
it is in -Wall is _good_ for this reason. :) No one is going to add
-fstrict-flex-arrays (at any level) without understanding what it does
and wanting those effects on -Warray-bounds.

-- 
Kees Cook


Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-18 Thread Qing Zhao via Gcc-patches
Hi, Richard,

Honestly, it’s very hard for me to decide what’s the best way to handle the 
interaction 
between -fstrict-flex-array=M and -Warray-bounds=N. 

Ideally,  -fstrict-flex-array=M should completely control the behavior of 
-Warray-bounds.
If possible, I prefer this solution.

However, -Warray-bounds is included in -Wall, and has been used extensively for 
a long time.
It’s not safe to change its default behavior. 

So, I guess that the bottom-line for this work is:

Keeping the default behavior of -Warray-bounds.

Is this correct understanding?


> On Nov 18, 2022, at 8:14 AM, Richard Biener  wrote:
> 
> On Tue, 8 Nov 2022, Qing Zhao wrote:
> 
>> '-Wstrict-flex-arrays'
>> Warn about inproper usages of flexible array members according to
>> the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
>> the trailing array field of a structure if it's available,
>> otherwise according to the LEVEL of the option
>> '-fstrict-flex-arrays=LEVEL'.
>> 
>> This option is effective only when LEVEL is bigger than 0.
>> Otherwise, it will be ignored with a warning.
>> 
>> when LEVEL=1, warnings will be issued for a trailing array
>> reference of a structure that have 2 or more elements if the
>> trailing array is referenced as a flexible array member.
>> 
>> when LEVEL=2, in addition to LEVEL=1, additional warnings will be
>> issued for a trailing one-element array reference of a structure if
>> the array is referenced as a flexible array member.
>> 
>> when LEVEL=3, in addition to LEVEL=2, additional warnings will be
>> issued for a trailing zero-length array reference of a structure if
>> the array is referenced as a flexible array member.
>> 
>> At the same time, keep -Warray-bounds=[1|2] warnings unchanged from
>> -fstrict-flex-arrays.
> 
> Looking at this, is this a way to avoid interpreting -Warray-bounds=N
> together with -fstrict-flex-arrays=M?  Won't this be just confusing to
> users?  Especially since -Wall includes -Warray-bounds and thus we'll
> diagnose
> 
> +  if (opts->x_warn_array_bounds)
> +if (opts->x_flag_strict_flex_arrays)
> +  {
> +   warning_at (UNKNOWN_LOCATION, 0,
> +   "%<-Warray-bounds%> is not impacted by "
> +   "%<-fstrict-flex-arrays%>");
> +  }
> 
> and do that even when -Wstrict-flex-arrays is given?

The basic idea here is:   -Warray-bounds=N will NOT be controlled by 
-fstrict-flex-array=M at all.
And the new -Wstrict-flex-array will be used to report warnings for different 
level of “M”. 

> 
> Would it be better/possible to add a note: to existing -Warray-bounds
> diagnostics on how the behavior is altered by -fstrict-flex-arrays?

If -Warray-bounds does not have the additional level “N” argument. It’s 
reasonable and natural for it to be controlled 
by the level of -fstrict-flex-arrays. 
> 
> I guess this will inevitably re-iterate the -fstrict-flex-arrays=N
> vs. -Warray-bounds=M discussion ...

Yes, that’s the most confusion and challenge part for this work… and took me a 
lot of thinking but still cannot
 find the best way to handle it…..
> 
> I think it would be better to stick with -Warray-bounds and flex
> its =2 mode to work according to -fstrict-flex-arrays=N instead of
> "out of bounds accesses to trailing struct members of one-element array 
> types" (thus, not add [1] but instead the cases that are not flex 
> arrays according to -fstrict-flex-arrays).

From my understanding, you suggested the following:

1. Keep -Warray-bounds default behavior.
i.e. when -Warray-bounds=1, it’s behavior will not be impacted by 
-fstrict-flex-array=M

2. When -Warray-bounds=2,  it’s behavior will be controlled by 
-fstrict-flex-array=M


Is the above understanding correct?

If yes, then the major question is:

When -Warray-bounds=2, -fstrict-flex-array = 0 or 1,2,  i.e, when the level of 
-fstrict-flex-array is lower or equal to 2. 
 [0] and [1] will be treated as flexible array member by -fstrict-flex-array, 
it’s conflict with how -Warray-bounds=2’s 
behavior on treating flexible array members.  Under such situation, which one 
has higher priority?


I have another idea now:

1. Keep -Warray-bounds=1 default behavior. 
2. Change the behavior of -Warray-bounds=2 from:

Current:
-Warray-bounds=2
This warning level also warns about out of bounds accesses to trailing struct 
members of one-element array types (see Zero Length) and about the intermediate 
results of pointer arithmetic that may yield out of bounds values. This warning 
level may give a larger number of false positives and is deactivated by default.

New:
-Warray-bounds=2
This warning level also warns  about the intermediate results of pointer 
arithmetic that may yield out of bounds values. This warning level may give a 
larger number of false positives and is deactivated by default.

i.e, delete the control on flexible array member from the level of 
-Warray-bounds. 

3. Use -fstrict-flex-arra

Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-18 Thread Richard Biener via Gcc-patches
On Tue, 8 Nov 2022, Qing Zhao wrote:

> '-Wstrict-flex-arrays'
>  Warn about inproper usages of flexible array members according to
>  the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
>  the trailing array field of a structure if it's available,
>  otherwise according to the LEVEL of the option
>  '-fstrict-flex-arrays=LEVEL'.
> 
>  This option is effective only when LEVEL is bigger than 0.
>  Otherwise, it will be ignored with a warning.
> 
>  when LEVEL=1, warnings will be issued for a trailing array
>  reference of a structure that have 2 or more elements if the
>  trailing array is referenced as a flexible array member.
> 
>  when LEVEL=2, in addition to LEVEL=1, additional warnings will be
>  issued for a trailing one-element array reference of a structure if
>  the array is referenced as a flexible array member.
> 
>  when LEVEL=3, in addition to LEVEL=2, additional warnings will be
>  issued for a trailing zero-length array reference of a structure if
>  the array is referenced as a flexible array member.
> 
> At the same time, keep -Warray-bounds=[1|2] warnings unchanged from
>  -fstrict-flex-arrays.

Looking at this, is this a way to avoid interpreting -Warray-bounds=N
together with -fstrict-flex-arrays=M?  Won't this be just confusing to
users?  Especially since -Wall includes -Warray-bounds and thus we'll
diagnose

+  if (opts->x_warn_array_bounds)
+if (opts->x_flag_strict_flex_arrays)
+  {
+   warning_at (UNKNOWN_LOCATION, 0,
+   "%<-Warray-bounds%> is not impacted by "
+   "%<-fstrict-flex-arrays%>");
+  }

and do that even when -Wstrict-flex-arrays is given?

Would it be better/possible to add a note: to existing -Warray-bounds
diagnostics on how the behavior is altered by -fstrict-flex-arrays?

I guess this will inevitably re-iterate the -fstrict-flex-arrays=N
vs. -Warray-bounds=M discussion ...

I think it would be better to stick with -Warray-bounds and flex
its =2 mode to work according to -fstrict-flex-arrays=N instead of
"out of bounds accesses to trailing struct members of one-element array 
types" (thus, not add [1] but instead the cases that are not flex 
arrays according to -fstrict-flex-arrays).

Richard.

> gcc/ChangeLog:
> 
>   * attribs.cc (strict_flex_array_level_of): New function.
>   * attribs.h (strict_flex_array_level_of): Prototype for new function.
>   * doc/invoke.texi: Document -Wstrict-flex-arrays option. Update
>   -fstrict-flex-arrays[=n] options.
>   * gimple-array-bounds.cc (array_bounds_checker::check_array_ref):
>   Issue warnings for -Wstrict-flex-arrays.
>   (get_up_bounds_for_array_ref): New function.
>   (check_out_of_bounds_and_warn): New function.
>   * opts.cc (finish_options): Issue warnings for unsupported combination
>   of -Warray-bounds and -fstrict-flex-arrays, -Wstrict_flex_arrays and
>   -fstrict-flex-array.
>   * tree-vrp.cc (execute_vrp): Enable the pass when
>   warn_strict_flex_array is true.
>   (execute_ranger_vrp): Likewise.
>   * tree.cc (array_ref_flexible_size_p): Add one new argument.
>   (component_ref_sam_type): New function.
>   (component_ref_size): Add one new argument,
>   * tree.h (array_ref_flexible_size_p): Update prototype.
>   (enum struct special_array_member): Add two new enum values.
>   (component_ref_sam_type): New prototype.
>   (component_ref_size): Update prototype.
> 
> gcc/c-family/ChangeLog:
> 
>   * c.opt (Wstrict-flex-arrays): New option.
> 
> gcc/c/ChangeLog:
> 
>   * c-decl.cc (is_flexible_array_member_p): Call new function
>   strict_flex_array_level_of.
> 
> gcc/testsuite/ChangeLog:
> 
>   * c-c++-common/Wstrict-flex-arrays.c: New test.
>   * c-c++-common/Wstrict-flex-arrays_2.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-2.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-3.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-4.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-5.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-6.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-7.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-8.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-9.c: New test.
>   * gcc.dg/Wstrict-flex-arrays.c: New test.
> ---
>  gcc/attribs.cc|  30 ++
>  gcc/attribs.h |   2 +
>  gcc/c-family/c.opt|   5 +
>  gcc/c/c-decl.cc   |  22 +-
>  gcc/doc/invoke.texi   |  33 ++-
>  gcc/gimple-array-bounds.cc| 264 +-
>  gcc/opts.cc   |  15 +
>  .../c-c++-common/Wstrict-flex-arrays.c|   9 +
>  .../c-c++-common/Wstrict-flex-arrays_2.c  |   9 +
>  gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c  |  46 +++
>  gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c

Re: [PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-15 Thread Qing Zhao via Gcc-patches
Ping on this patch.

thanks.

Qing

> On Nov 8, 2022, at 9:51 AM, Qing Zhao  wrote:
> 
> '-Wstrict-flex-arrays'
> Warn about inproper usages of flexible array members according to
> the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
> the trailing array field of a structure if it's available,
> otherwise according to the LEVEL of the option
> '-fstrict-flex-arrays=LEVEL'.
> 
> This option is effective only when LEVEL is bigger than 0.
> Otherwise, it will be ignored with a warning.
> 
> when LEVEL=1, warnings will be issued for a trailing array
> reference of a structure that have 2 or more elements if the
> trailing array is referenced as a flexible array member.
> 
> when LEVEL=2, in addition to LEVEL=1, additional warnings will be
> issued for a trailing one-element array reference of a structure if
> the array is referenced as a flexible array member.
> 
> when LEVEL=3, in addition to LEVEL=2, additional warnings will be
> issued for a trailing zero-length array reference of a structure if
> the array is referenced as a flexible array member.
> 
> At the same time, keep -Warray-bounds=[1|2] warnings unchanged from
> -fstrict-flex-arrays.
> 
> gcc/ChangeLog:
> 
>   * attribs.cc (strict_flex_array_level_of): New function.
>   * attribs.h (strict_flex_array_level_of): Prototype for new function.
>   * doc/invoke.texi: Document -Wstrict-flex-arrays option. Update
>   -fstrict-flex-arrays[=n] options.
>   * gimple-array-bounds.cc (array_bounds_checker::check_array_ref):
>   Issue warnings for -Wstrict-flex-arrays.
>   (get_up_bounds_for_array_ref): New function.
>   (check_out_of_bounds_and_warn): New function.
>   * opts.cc (finish_options): Issue warnings for unsupported combination
>   of -Warray-bounds and -fstrict-flex-arrays, -Wstrict_flex_arrays and
>   -fstrict-flex-array.
>   * tree-vrp.cc (execute_vrp): Enable the pass when
>   warn_strict_flex_array is true.
>   (execute_ranger_vrp): Likewise.
>   * tree.cc (array_ref_flexible_size_p): Add one new argument.
>   (component_ref_sam_type): New function.
>   (component_ref_size): Add one new argument,
>   * tree.h (array_ref_flexible_size_p): Update prototype.
>   (enum struct special_array_member): Add two new enum values.
>   (component_ref_sam_type): New prototype.
>   (component_ref_size): Update prototype.
> 
> gcc/c-family/ChangeLog:
> 
>   * c.opt (Wstrict-flex-arrays): New option.
> 
> gcc/c/ChangeLog:
> 
>   * c-decl.cc (is_flexible_array_member_p): Call new function
>   strict_flex_array_level_of.
> 
> gcc/testsuite/ChangeLog:
> 
>   * c-c++-common/Wstrict-flex-arrays.c: New test.
>   * c-c++-common/Wstrict-flex-arrays_2.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-2.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-3.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-4.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-5.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-6.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-7.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-8.c: New test.
>   * gcc.dg/Wstrict-flex-arrays-9.c: New test.
>   * gcc.dg/Wstrict-flex-arrays.c: New test.
> ---
> gcc/attribs.cc|  30 ++
> gcc/attribs.h |   2 +
> gcc/c-family/c.opt|   5 +
> gcc/c/c-decl.cc   |  22 +-
> gcc/doc/invoke.texi   |  33 ++-
> gcc/gimple-array-bounds.cc| 264 +-
> gcc/opts.cc   |  15 +
> .../c-c++-common/Wstrict-flex-arrays.c|   9 +
> .../c-c++-common/Wstrict-flex-arrays_2.c  |   9 +
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c  |  46 +++
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c  |  46 +++
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-4.c  |  49 
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-5.c  |  48 
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-6.c  |  48 
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-7.c  |  50 
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-8.c  |  49 
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays-9.c  |  49 
> gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c|  46 +++
> gcc/tree-vrp.cc   |   6 +-
> gcc/tree.cc   | 165 ---
> gcc/tree.h|  15 +-
> 21 files changed, 870 insertions(+), 136 deletions(-)
> create mode 100644 gcc/testsuite/c-c++-common/Wstrict-flex-arrays.c
> create mode 100644 gcc/testsuite/c-c++-common/Wstrict-flex-arrays_2.c
> create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c
> create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c
> create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-4.c
> create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-5.c
>

[PATCH 2/2] Add a new warning option -Wstrict-flex-arrays.

2022-11-08 Thread Qing Zhao via Gcc-patches
'-Wstrict-flex-arrays'
 Warn about inproper usages of flexible array members according to
 the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to
 the trailing array field of a structure if it's available,
 otherwise according to the LEVEL of the option
 '-fstrict-flex-arrays=LEVEL'.

 This option is effective only when LEVEL is bigger than 0.
 Otherwise, it will be ignored with a warning.

 when LEVEL=1, warnings will be issued for a trailing array
 reference of a structure that have 2 or more elements if the
 trailing array is referenced as a flexible array member.

 when LEVEL=2, in addition to LEVEL=1, additional warnings will be
 issued for a trailing one-element array reference of a structure if
 the array is referenced as a flexible array member.

 when LEVEL=3, in addition to LEVEL=2, additional warnings will be
 issued for a trailing zero-length array reference of a structure if
 the array is referenced as a flexible array member.

At the same time, keep -Warray-bounds=[1|2] warnings unchanged from
 -fstrict-flex-arrays.

gcc/ChangeLog:

* attribs.cc (strict_flex_array_level_of): New function.
* attribs.h (strict_flex_array_level_of): Prototype for new function.
* doc/invoke.texi: Document -Wstrict-flex-arrays option. Update
-fstrict-flex-arrays[=n] options.
* gimple-array-bounds.cc (array_bounds_checker::check_array_ref):
Issue warnings for -Wstrict-flex-arrays.
(get_up_bounds_for_array_ref): New function.
(check_out_of_bounds_and_warn): New function.
* opts.cc (finish_options): Issue warnings for unsupported combination
of -Warray-bounds and -fstrict-flex-arrays, -Wstrict_flex_arrays and
-fstrict-flex-array.
* tree-vrp.cc (execute_vrp): Enable the pass when
warn_strict_flex_array is true.
(execute_ranger_vrp): Likewise.
* tree.cc (array_ref_flexible_size_p): Add one new argument.
(component_ref_sam_type): New function.
(component_ref_size): Add one new argument,
* tree.h (array_ref_flexible_size_p): Update prototype.
(enum struct special_array_member): Add two new enum values.
(component_ref_sam_type): New prototype.
(component_ref_size): Update prototype.

gcc/c-family/ChangeLog:

* c.opt (Wstrict-flex-arrays): New option.

gcc/c/ChangeLog:

* c-decl.cc (is_flexible_array_member_p): Call new function
strict_flex_array_level_of.

gcc/testsuite/ChangeLog:

* c-c++-common/Wstrict-flex-arrays.c: New test.
* c-c++-common/Wstrict-flex-arrays_2.c: New test.
* gcc.dg/Wstrict-flex-arrays-2.c: New test.
* gcc.dg/Wstrict-flex-arrays-3.c: New test.
* gcc.dg/Wstrict-flex-arrays-4.c: New test.
* gcc.dg/Wstrict-flex-arrays-5.c: New test.
* gcc.dg/Wstrict-flex-arrays-6.c: New test.
* gcc.dg/Wstrict-flex-arrays-7.c: New test.
* gcc.dg/Wstrict-flex-arrays-8.c: New test.
* gcc.dg/Wstrict-flex-arrays-9.c: New test.
* gcc.dg/Wstrict-flex-arrays.c: New test.
---
 gcc/attribs.cc|  30 ++
 gcc/attribs.h |   2 +
 gcc/c-family/c.opt|   5 +
 gcc/c/c-decl.cc   |  22 +-
 gcc/doc/invoke.texi   |  33 ++-
 gcc/gimple-array-bounds.cc| 264 +-
 gcc/opts.cc   |  15 +
 .../c-c++-common/Wstrict-flex-arrays.c|   9 +
 .../c-c++-common/Wstrict-flex-arrays_2.c  |   9 +
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c  |  46 +++
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c  |  46 +++
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-4.c  |  49 
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-5.c  |  48 
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-6.c  |  48 
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-7.c  |  50 
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-8.c  |  49 
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-9.c  |  49 
 gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c|  46 +++
 gcc/tree-vrp.cc   |   6 +-
 gcc/tree.cc   | 165 ---
 gcc/tree.h|  15 +-
 21 files changed, 870 insertions(+), 136 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/Wstrict-flex-arrays.c
 create mode 100644 gcc/testsuite/c-c++-common/Wstrict-flex-arrays_2.c
 create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c
 create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c
 create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-4.c
 create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-5.c
 create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-6.c
 create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-7.c
 create mode 100644 gcc/testsuite/gcc.dg/Ws