aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vrp.cc
diff options
context:
space:
mode:
authorQing Zhao <qing.zhao@oracle.com>2022-12-16 17:25:42 +0000
committerQing Zhao <qing.zhao@oracle.com>2022-12-16 17:25:42 +0000
commit2a27ae32fabf85685ffff758459d7ec284ccb95a (patch)
treef454c76a179f030d6b89947de1c233d6934dc7d3 /gcc/tree-vrp.cc
parent9bb7864877ab05bf951fad66c934845351b271ce (diff)
downloadgcc-2a27ae32fabf85685ffff758459d7ec284ccb95a.zip
gcc-2a27ae32fabf85685ffff758459d7ec284ccb95a.tar.gz
gcc-2a27ae32fabf85685ffff758459d7ec284ccb95a.tar.bz2
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.
Diffstat (limited to 'gcc/tree-vrp.cc')
-rw-r--r--gcc/tree-vrp.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index 3846dc1..e6c6c5a 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -1087,7 +1087,7 @@ execute_ranger_vrp (struct function *fun, bool warn_array_bounds_p,
if (dump_file && (dump_flags & TDF_DETAILS))
ranger->dump (dump_file);
- if (warn_array_bounds && warn_array_bounds_p)
+ if ((warn_array_bounds || warn_strict_flex_arrays) && warn_array_bounds_p)
{
// Set all edges as executable, except those ranger says aren't.
int non_exec_flag = ranger->non_executable_edge_flag;