diff options
author | Qing Zhao <qing.zhao@oracle.com> | 2023-01-13 15:08:00 +0000 |
---|---|---|
committer | Qing Zhao <qing.zhao@oracle.com> | 2023-01-13 15:08:00 +0000 |
commit | a3e8727b70f546dc82941391f3951188a0339e08 (patch) | |
tree | e5373b5b514284f10344daf67a0c693c44c26d38 /gcc/gimple-array-bounds.cc | |
parent | 450eb6b3b5b544d26da2535228ce03f9656a13a5 (diff) | |
download | gcc-a3e8727b70f546dc82941391f3951188a0339e08.zip gcc-a3e8727b70f546dc82941391f3951188a0339e08.tar.gz gcc-a3e8727b70f546dc82941391f3951188a0339e08.tar.bz2 |
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.
Diffstat (limited to 'gcc/gimple-array-bounds.cc')
-rw-r--r-- | gcc/gimple-array-bounds.cc | 46 |
1 files changed, 9 insertions, 37 deletions
diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc index 116200a..66fd46e 100644 --- a/gcc/gimple-array-bounds.cc +++ b/gcc/gimple-array-bounds.cc @@ -350,18 +350,14 @@ array_bounds_checker::check_array_ref (location_t location, tree ref, /* Set to the type of the special array member for a COMPONENT_REF. */ special_array_member sam{ }; - + tree afield_decl = NULL_TREE; tree arg = TREE_OPERAND (ref, 0); - const bool compref = TREE_CODE (arg) == COMPONENT_REF; - unsigned int strict_flex_array_level = flag_strict_flex_arrays; - if (compref) + if (TREE_CODE (arg) == COMPONENT_REF) { /* Try to determine special array member type for this COMPONENT_REF. */ sam = component_ref_sam_type (arg); - /* Get the level of strict_flex_array for this array field. */ - tree afield_decl = TREE_OPERAND (arg, 1); - strict_flex_array_level = strict_flex_array_level_of (afield_decl); + afield_decl = TREE_OPERAND (arg, 1); } get_up_bounds_for_array_ref (ref, &decl, &up_bound, &up_bound_p1); @@ -412,39 +408,15 @@ array_bounds_checker::check_array_ref (location_t location, tree ref, /* issue warnings for -Wstrict-flex-arrays according to the level of flag_strict_flex_arrays. */ - if (out_of_bound && warn_strict_flex_arrays) - switch (strict_flex_array_level) - { - case 3: - /* Issue additional warnings for trailing arrays [0]. */ - if (sam == special_array_member::trail_0) + if ((out_of_bound && warn_strict_flex_arrays) + && (((sam == special_array_member::trail_0) + || (sam == special_array_member::trail_1) + || (sam == special_array_member::trail_n)) + && DECL_NOT_FLEXARRAY (afield_decl))) warned = warning_at (location, OPT_Wstrict_flex_arrays, "trailing array %qT should not be used as " - "a flexible array member for level 3", + "a flexible array member", artype); - /* FALLTHROUGH. */ - case 2: - /* Issue additional warnings for trailing arrays [1]. */ - if (sam == special_array_member::trail_1) - warned = warning_at (location, OPT_Wstrict_flex_arrays, - "trailing array %qT should not be used as " - "a flexible array member for level 2 and " - "above", artype); - /* FALLTHROUGH. */ - case 1: - /* Issue warnings for trailing arrays [n]. */ - if (sam == special_array_member::trail_n) - warned = warning_at (location, OPT_Wstrict_flex_arrays, - "trailing array %qT should not be used as " - "a flexible array member for level 1 and " - "above", artype); - break; - case 0: - /* Do nothing. */ - break; - default: - gcc_unreachable (); - } /* Avoid more warnings when checking more significant subscripts of the same expression. */ |