aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.cc
diff options
context:
space:
mode:
authorQing Zhao <qing.zhao@oracle.com>2023-01-13 15:08:00 +0000
committerQing Zhao <qing.zhao@oracle.com>2023-01-13 15:08:00 +0000
commita3e8727b70f546dc82941391f3951188a0339e08 (patch)
treee5373b5b514284f10344daf67a0c693c44c26d38 /gcc/tree.cc
parent450eb6b3b5b544d26da2535228ce03f9656a13a5 (diff)
downloadgcc-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/tree.cc')
-rw-r--r--gcc/tree.cc37
1 files changed, 7 insertions, 30 deletions
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 78b64ee..7473912 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -13074,38 +13074,15 @@ component_ref_size (tree ref, special_array_member *sam /* = NULL */)
|| *sam == special_array_member::trail_n)
return memsize;
- /* flag_strict_flex_arrays will control how to treat
- the trailing arrays as flexiable array members. */
-
tree afield_decl = TREE_OPERAND (ref, 1);
- unsigned int strict_flex_array_level
- = strict_flex_array_level_of (afield_decl);
-
- switch (strict_flex_array_level)
- {
- case 3:
- /* Treaing 0-length trailing arrays as normal array. */
- if (*sam == special_array_member::trail_0)
- return size_zero_node;
- /* FALLTHROUGH. */
- case 2:
- /* Treating 1-element trailing arrays as normal array. */
- if (*sam == special_array_member::trail_1)
- return memsize;
- /* FALLTHROUGH. */
- case 1:
- /* Treating 2-or-more elements trailing arrays as normal
- array. */
- if (*sam == special_array_member::trail_n)
- return memsize;
- /* FALLTHROUGH. */
- case 0:
- break;
- default:
- gcc_unreachable ();
- }
+ gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
+ /* if the trailing array is a not a flexible array member, treat it as
+ a normal array. */
+ if (DECL_NOT_FLEXARRAY (afield_decl)
+ && *sam != special_array_member::int_0)
+ return memsize;
- if (*sam == special_array_member::int_0)
+ if (*sam == special_array_member::int_0)
memsize = NULL_TREE;
/* For a reference to a flexible array member of a union