aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.h
diff options
context:
space:
mode:
authorQing Zhao <qing.zhao@oracle.com>2022-12-06 18:50:04 +0000
committerQing Zhao <qing.zhao@oracle.com>2022-12-06 18:50:04 +0000
commit710c9676520dfd38b4bfdcc937ce026ed89921d6 (patch)
tree81a6bc70c710cba93ab79a61180ce822fe31ae13 /gcc/tree.h
parentdcfc7ac94dbcf6c86c0c58ce6dc1d8bd853e4093 (diff)
downloadgcc-710c9676520dfd38b4bfdcc937ce026ed89921d6.zip
gcc-710c9676520dfd38b4bfdcc937ce026ed89921d6.tar.gz
gcc-710c9676520dfd38b4bfdcc937ce026ed89921d6.tar.bz2
Update -Warray-bounds with -fstrict-flex-arrays.
A. add the following to clarify the relationship between -Warray-bounds and the LEVEL of -fstrict-flex-array: By default, the trailing array of a structure will be treated as a flexible array member by '-Warray-bounds' or '-Warray-bounds=N' if it is declared as either a flexible array member per C99 standard onwards ('[]'), a GCC zero-length array extension ('[0]'), or an one-element array ('[1]'). As a result, out of bounds subscripts or offsets into zero-length arrays or one-element arrays are not warned by default. You can add the option '-fstrict-flex-arrays' or '-fstrict-flex-arrays=LEVEL' to control how this option treat trailing array of a structure as a flexible array member. when LEVEL<=1, no change to the default behavior. when LEVEL=2, additional warnings will be issued for out of bounds subscripts or offsets into one-element arrays; when LEVEL=3, in addition to LEVEL=2, additional warnings will be issued for out of bounds subscripts or offsets into zero-length arrays. B. change -Warray-bounds=2 to exclude its control on how to treat trailing arrays as flexible array members: '-Warray-bounds=2' This warning level also warns about the intermediate results of pointer arithmetic that may yield out of bounds values. This warning level may give a larger number of false positives and is deactivated by default. gcc/ChangeLog: * attribs.cc (strict_flex_array_level_of): New function. * attribs.h (strict_flex_array_level_of): Prototype for new function. * doc/invoke.texi: Update -Warray-bounds by specifying the impact from -fstrict-flex-arrays. Also update -Warray-bounds=2 by eliminating its impact on treating trailing arrays as flexible array members. * gimple-array-bounds.cc (get_up_bounds_for_array_ref): New function. (check_out_of_bounds_and_warn): New function. (array_bounds_checker::check_array_ref): Update with call to the above new functions. * tree.cc (array_ref_flexible_size_p): Add one new argument. (component_ref_sam_type): New function. (component_ref_size): Control with level of strict-flex-array. * tree.h (array_ref_flexible_size_p): Update prototype. (enum struct special_array_member): Add two new enum values. (component_ref_sam_type): New prototype. gcc/c/ChangeLog: * c-decl.cc (is_flexible_array_member_p): Call new function strict_flex_array_level_of. gcc/testsuite/ChangeLog: * gcc.dg/Warray-bounds-11.c: Update warnings for -Warray-bounds=2. * gcc.dg/Warray-bounds-flex-arrays-1.c: New test. * gcc.dg/Warray-bounds-flex-arrays-2.c: New test. * gcc.dg/Warray-bounds-flex-arrays-3.c: New test. * gcc.dg/Warray-bounds-flex-arrays-4.c: New test. * gcc.dg/Warray-bounds-flex-arrays-5.c: New test. * gcc.dg/Warray-bounds-flex-arrays-6.c: New test.
Diffstat (limited to 'gcc/tree.h')
-rw-r--r--gcc/tree.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/gcc/tree.h b/gcc/tree.h
index 4a19de1..23223ca 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -5553,22 +5553,26 @@ extern tree array_ref_low_bound (tree);
/* Returns true if REF is an array reference, a component reference,
or a memory reference to an array whose actual size might be larger
than its upper bound implies. */
-extern bool array_ref_flexible_size_p (tree);
+extern bool array_ref_flexible_size_p (tree, bool * = NULL);
/* Return a tree representing the offset, in bytes, of the field referenced
by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
extern tree component_ref_field_offset (tree);
-/* Describes a "special" array member due to which component_ref_size
- returns null. */
+/* Describes a "special" array member for a COMPONENT_REF. */
enum struct special_array_member
{
none, /* Not a special array member. */
int_0, /* Interior array member with size zero. */
trail_0, /* Trailing array member with size zero. */
- trail_1 /* Trailing array member with one element. */
+ trail_1, /* Trailing array member with one element. */
+ trail_n, /* Trailing array member with two or more elements. */
+ int_n /* Interior array member with one or more elements. */
};
+/* Determines the special array member type for a COMPONENT_REF. */
+extern special_array_member component_ref_sam_type (tree);
+
/* Return the size of the member referenced by the COMPONENT_REF, using
its initializer expression if necessary in order to determine the size
of an initialized flexible array member. The size might be zero for