aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-array-bounds.cc
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-07-27 13:54:50 -0600
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-17 13:19:52 -0300
commita76c1d62979c58606a134dcfbf9be977d68331f6 (patch)
treedcd434e10d733fc1b2ff521950d07297c505bb39 /gcc/gimple-array-bounds.cc
parentdf145ecbbe2171727f8ae87218816ec846aabd12 (diff)
downloadgcc-a76c1d62979c58606a134dcfbf9be977d68331f6.zip
gcc-a76c1d62979c58606a134dcfbf9be977d68331f6.tar.gz
gcc-a76c1d62979c58606a134dcfbf9be977d68331f6.tar.bz2
Diagnose just-past-the-end references for minor array bounds.
Resolves: PR tree-optimization/84079 - missing -Warray-bounds taking the address of past-the-end element of a multidimensional array gcc/ChangeLog: PR tree-optimization/84079 * gimple-array-bounds.cc (array_bounds_checker::check_addr_expr): Only allow just-past-the-end references for the most significant array bound. gcc/testsuite/ChangeLog: PR tree-optimization/84079 * gcc.dg/Warray-bounds-62.c: New test.
Diffstat (limited to 'gcc/gimple-array-bounds.cc')
-rw-r--r--gcc/gimple-array-bounds.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc
index 352d074..c2dd666 100644
--- a/gcc/gimple-array-bounds.cc
+++ b/gcc/gimple-array-bounds.cc
@@ -519,14 +519,21 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref,
void
array_bounds_checker::check_addr_expr (location_t location, tree t)
{
+ /* For the most significant subscript only, accept taking the address
+ of the just-past-the-end element. */
+ bool ignore_off_by_one = true;
+
/* Check each ARRAY_REF and MEM_REF in the reference chain. */
do
{
bool warned = false;
if (TREE_CODE (t) == ARRAY_REF)
- warned = check_array_ref (location, t, true /*ignore_off_by_one*/);
+ {
+ warned = check_array_ref (location, t, ignore_off_by_one);
+ ignore_off_by_one = false;
+ }
else if (TREE_CODE (t) == MEM_REF)
- warned = check_mem_ref (location, t, true /*ignore_off_by_one*/);
+ warned = check_mem_ref (location, t, ignore_off_by_one);
if (warned)
TREE_NO_WARNING (t) = true;