Hi, Sid, Thanks a lot for the input.
After more thinking based on your and Kees’ comments, I have the following thought: 1. -fstrict-flex-arrays=level should control both GCC code gen and warnings consistently; 2. We need warnings specifically for -fstrict-flex-arrays=level to report any misuse of flexible array corresponding to the “level” to gradually encourage language standard. So, based on the above two, I think what I did in this current patch is correct: 1. We eliminate the control from -Warray-bounds=level on treating flex arrays, now only "-fstrict-flex-arrasy=level" controls how the warning treating the flex arrays. 2. We add a separate new warning -Wstrict-flex-arrays to report any misuse corresponding to the different level of -fstrict-flex-arrays. Although we can certainly merge these new warnings into -Warray-bounds, however, as Sid mentioned, -Warray-bounds does issue a lot more warnings than just flexible arrays misuse. I think it’s necessary To provide a seperate warning to only issue flexible array misuse. Let me know if you have any more comments on this. thanks. Qing > On Dec 1, 2022, at 2:45 PM, Siddhesh Poyarekar <siddh...@gotplt.org> wrote: > > On 2022-12-01 11:42, Kees Cook wrote: >> On Wed, Nov 30, 2022 at 02:25:56PM +0000, 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, -Warray-bounds is updated: >> Why is there both -Wstrict-flex-arrays and -Warray-bounds? I thought >> only the latter was going to exist? > > Oh my understanding of the consensus was to move flex array related diagnosis > from -Warray-bounds to -Wstring-flex-arrays as Qing has done. If only the > former exists then instead of removing the flex array related statement in > the documentation as Richard suggested, we need to enhance it to say that > behaviour of -Warray-bounds will depend on -fstrict-flex-arrays. > > -Warray-bounds does diagnosis beyond just flexible arrays, in case that's the > confusion. > > Sid