Replace flag_strict_flex_arrays with DECL_NOT_FLEXARRAY in middle-end.
authorQing Zhao <qing.zhao@oracle.com>
Fri, 13 Jan 2023 15:08:00 +0000 (15:08 +0000)
committerQing Zhao <qing.zhao@oracle.com>
Fri, 13 Jan 2023 15:08:00 +0000 (15:08 +0000)
commita3e8727b70f546dc82941391f3951188a0339e08
treee5373b5b514284f10344daf67a0c693c44c26d38
parent450eb6b3b5b544d26da2535228ce03f9656a13a5
Replace flag_strict_flex_arrays with DECL_NOT_FLEXARRAY in middle-end.

We should not directly check flag_strict_flex_arrays in the
middle end. Instead, check DECL_NOT_FLEXARRAY(array_field_decl) which is set
by C/C++ FEs according to -fstrict-flex-arrays and the corresponding
attribute attached to the array_field.

As a result, We will lose the LEVEL information of -fstrict-flex-arrays in
the middle end. -Wstrict-flex-arrays will not be able to issue such
information. update the testing cases accordingly.

gcc/ChangeLog:

* attribs.cc (strict_flex_array_level_of): Move this function to ...
* attribs.h (strict_flex_array_level_of): Remove the declaration.
* gimple-array-bounds.cc (array_bounds_checker::check_array_ref):
replace the referece to strict_flex_array_level_of with
DECL_NOT_FLEXARRAY.
* tree.cc (component_ref_size): Likewise.

gcc/c/ChangeLog:

* c-decl.cc (strict_flex_array_level_of): ... here.

gcc/testsuite/ChangeLog:

* gcc.dg/Warray-bounds-flex-arrays-1.c: Delete the level information
from the message issued by -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.
* gcc.dg/Wstrict-flex-arrays-2.c: Likewise.
* gcc.dg/Wstrict-flex-arrays-3.c: Likewise.
* gcc.dg/Wstrict-flex-arrays.c: Likewise.
14 files changed:
gcc/attribs.cc
gcc/attribs.h
gcc/c/c-decl.cc
gcc/gimple-array-bounds.cc
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
gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c
gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c
gcc/tree.cc