diff options
author | Martin Sebor <msebor@redhat.com> | 2019-11-05 16:20:44 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-11-05 09:20:44 -0700 |
commit | 361d4a9eb6b397f3401b7693ee9fbc032e95a0f0 (patch) | |
tree | d0efeac99cf67e900fd19921105e9211998dbe51 /gcc/tree-vrp.c | |
parent | 02bf7e6fa219f939b3225c54fbe8bab2133b1aeb (diff) | |
download | gcc-361d4a9eb6b397f3401b7693ee9fbc032e95a0f0.zip gcc-361d4a9eb6b397f3401b7693ee9fbc032e95a0f0.tar.gz gcc-361d4a9eb6b397f3401b7693ee9fbc032e95a0f0.tar.bz2 |
PR middle-end/92341 - missing -Warray-bounds indexing past the end of a compound literal
PR middle-end/92341 - missing -Warray-bounds indexing past the end of a compound literal
PR middle-end/82612 - missing -Warray-bounds on a non-zero offset from the address of a non-array object
gcc/testsuite/ChangeLog:
PR middle-end/92341
PR middle-end/82612
* g++.dg/warn/Warray-bounds-4.C: Adjust text of expected warning.
* gcc.dg/Warray-bounds-53.c: New test.
* gcc.dg/Warray-bounds-54.c: New test.
gcc/ChangeLog:
PR middle-end/92341
PR middle-end/82612
* tree-sra.c (get_access_for_expr): Fail for out-of-bounds offsets.
* tree-vrp.c (vrp_prop::check_array_ref): Correct index and text
of message printed in a warning for empty arrays.
(vrp_prop::check_mem_ref): Also handle function parameters and
empty arrays.
From-SVN: r277851
Diffstat (limited to 'gcc/tree-vrp.c')
-rw-r--r-- | gcc/tree-vrp.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 1328707..940ed9c 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -4083,18 +4083,18 @@ bool vrp_prop::check_array_ref (location_t location, tree ref, bool ignore_off_by_one) { - tree low_sub, up_sub; - tree low_bound, up_bound, up_bound_p1; - if (TREE_NO_WARNING (ref)) return false; - low_sub = up_sub = TREE_OPERAND (ref, 1); - up_bound = array_ref_up_bound (ref); + tree low_sub = TREE_OPERAND (ref, 1); + tree up_sub = low_sub; + tree up_bound = array_ref_up_bound (ref); /* Set for accesses to interior zero-length arrays. */ bool interior_zero_len = false; + tree up_bound_p1; + if (!up_bound || TREE_CODE (up_bound) != INTEGER_CST || (warn_array_bounds < 2 @@ -4148,7 +4148,7 @@ vrp_prop::check_array_ref (location_t location, tree ref, up_bound_p1 = int_const_binop (PLUS_EXPR, up_bound, build_int_cst (TREE_TYPE (up_bound), 1)); - low_bound = array_ref_low_bound (ref); + tree low_bound = array_ref_low_bound (ref); tree artype = TREE_TYPE (TREE_OPERAND (ref, 0)); @@ -4157,8 +4157,8 @@ vrp_prop::check_array_ref (location_t location, tree ref, /* Empty array. */ if (up_bound && tree_int_cst_equal (low_bound, up_bound_p1)) warned = warning_at (location, OPT_Warray_bounds, - "array subscript %E is above array bounds of %qT", - low_bound, artype); + "array subscript %E is outside array bounds of %qT", + low_sub, artype); const value_range_equiv *vr = NULL; if (TREE_CODE (low_sub) == SSA_NAME) @@ -4372,6 +4372,7 @@ vrp_prop::check_mem_ref (location_t location, tree ref, { arg = TREE_OPERAND (arg, 0); if (TREE_CODE (arg) != STRING_CST + && TREE_CODE (arg) != PARM_DECL && TREE_CODE (arg) != VAR_DECL) return false; } @@ -4455,7 +4456,9 @@ vrp_prop::check_mem_ref (location_t location, tree ref, if (ignore_off_by_one) ubound += 1; - if (offrange[0] >= ubound || offrange[1] < arrbounds[0]) + if (arrbounds[0] == arrbounds[1] + || offrange[0] >= ubound + || offrange[1] < arrbounds[0]) { /* Treat a reference to a non-array object as one to an array of a single element. */ |