]> git.ipfire.org Git - thirdparty/gcc.git/commit
Add a new warning option -Wstrict-flex-arrays.
authorQing Zhao <qing.zhao@oracle.com>
Fri, 16 Dec 2022 17:25:42 +0000 (17:25 +0000)
committerQing Zhao <qing.zhao@oracle.com>
Fri, 16 Dec 2022 17:25:42 +0000 (17:25 +0000)
commit2a27ae32fabf85685ffff758459d7ec284ccb95a
treef454c76a179f030d6b89947de1c233d6934dc7d3
parent9bb7864877ab05bf951fad66c934845351b271ce
Add a new warning option -Wstrict-flex-arrays.

'-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.
15 files changed:
gcc/c-family/c.opt
gcc/doc/invoke.texi
gcc/gimple-array-bounds.cc
gcc/opts.cc
gcc/testsuite/c-c++-common/Wstrict-flex-arrays.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-1.c
gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-2.c
gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-3.c
gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-4.c
gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-5.c
gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-6.c
gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c [new file with mode: 0644]
gcc/tree-vrp.cc