From 1e24c0c9ddebec28bc40cc0346d268480c710346 Mon Sep 17 00:00:00 2001 From: rguenth Date: Tue, 11 Dec 2012 10:06:15 +0000 Subject: [PATCH] 2012-12-11 Richard Biener PR tree-optimization/55079 * tree-vrp.c (extract_range_from_binary_expr_1): Handle MAX/MIN_EXPR for more cases. (register_edge_assert_for_2): Register asserts for post-in/decrement tests. (check_array_ref): Dump what expression we emit array bound warnings for. (search_for_addr_array): Likewise. * gcc.dg/Warray-bounds-9.c: New testcase. * gcc.dg/Warray-bounds-10.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-1.c: Adjust. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194388 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 11 ++++ gcc/testsuite/ChangeLog | 7 ++ gcc/testsuite/gcc.dg/Warray-bounds-10.c | 25 +++++++ gcc/testsuite/gcc.dg/Warray-bounds-9.c | 19 ++++++ gcc/tree-vrp.c | 111 ++++++++++++++++++++++++++++---- 5 files changed, 162 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Warray-bounds-10.c create mode 100644 gcc/testsuite/gcc.dg/Warray-bounds-9.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index eef5504..fc1a827 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2012-12-11 Richard Biener + + PR tree-optimization/55079 + * tree-vrp.c (extract_range_from_binary_expr_1): Handle MAX/MIN_EXPR + for more cases. + (register_edge_assert_for_2): Register asserts for post-in/decrement + tests. + (check_array_ref): Dump what expression we emit array bound + warnings for. + (search_for_addr_array): Likewise. + 2012-12-11 Eric Botcazou * tree-ssa-loop-ivopts.c (prepare_decl_rtl) : Generate RTL diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 481bbaa..3e81e76 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2012-12-11 Richard Biener + + PR tree-optimization/55079 + * gcc.dg/Warray-bounds-9.c: New testcase. + * gcc.dg/Warray-bounds-10.c: Likewise. + * gcc.dg/tree-ssa/ssa-pre-1.c: Adjust. + 2012-12-10 Janus Weil PR fortran/52909 diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-10.c b/gcc/testsuite/gcc.dg/Warray-bounds-10.c new file mode 100644 index 0000000..5fd6e6f --- /dev/null +++ b/gcc/testsuite/gcc.dg/Warray-bounds-10.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -Warray-bounds" } */ + +int f(unsigned len, int buflen) +{ + unsigned taillen; + unsigned slen; + unsigned i; + int b[17]; /* needed <= 17 to trigger Warning */ + int j = 0; /* needed to trigger Warning */ + + b[0] = 0; + taillen= buflen & 7; /* taillen [0..7] */ + + if(taillen) { /* taillen [1..7] */ + slen= 8 - taillen; /* slen [7..1] */ + if (lensrc) + continue; + + if (!is_gimple_assign (use_stmt)) + continue; + + enum tree_code code = gimple_assign_rhs_code (use_stmt); + if (code != PLUS_EXPR + && code != MINUS_EXPR) + continue; + + tree cst = gimple_assign_rhs2 (use_stmt); + if (TREE_CODE (cst) != INTEGER_CST) + continue; + + tree name2 = gimple_assign_lhs (use_stmt); + if (live_on_edge (e, name2)) + { + cst = int_const_binop (code, val, cst); + register_new_assert_for (name2, name2, comp_code, cst, + NULL, e, bsi); + retval = true; + } + } + } + if (TREE_CODE_CLASS (comp_code) == tcc_comparison && TREE_CODE (val) == INTEGER_CST) { @@ -5943,6 +6012,11 @@ check_array_ref (location_t location, tree ref, bool ignore_off_by_one) : (tree_int_cst_lt (up_bound, up_sub) || tree_int_cst_equal (up_bound_p1, up_sub)))) { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Array bound warning for "); + dump_generic_expr (MSG_NOTE, TDF_SLIM, ref); + } warning_at (location, OPT_Warray_bounds, "array subscript is above array bounds"); TREE_NO_WARNING (ref) = 1; @@ -5950,6 +6024,11 @@ check_array_ref (location_t location, tree ref, bool ignore_off_by_one) else if (TREE_CODE (low_sub) == INTEGER_CST && tree_int_cst_lt (low_sub, low_bound)) { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Array bound warning for "); + dump_generic_expr (MSG_NOTE, TDF_SLIM, ref); + } warning_at (location, OPT_Warray_bounds, "array subscript is below array bounds"); TREE_NO_WARNING (ref) = 1; @@ -6018,6 +6097,11 @@ search_for_addr_array (tree t, location_t location) idx = idx.sdiv (tree_to_double_int (el_sz), TRUNC_DIV_EXPR); if (idx.slt (double_int_zero)) { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Array bound warning for "); + dump_generic_expr (MSG_NOTE, TDF_SLIM, t); + } warning_at (location, OPT_Warray_bounds, "array subscript is below array bounds"); TREE_NO_WARNING (t) = 1; @@ -6026,6 +6110,11 @@ search_for_addr_array (tree t, location_t location) - tree_to_double_int (low_bound) + double_int_one)) { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Array bound warning for "); + dump_generic_expr (MSG_NOTE, TDF_SLIM, t); + } warning_at (location, OPT_Warray_bounds, "array subscript is above array bounds"); TREE_NO_WARNING (t) = 1; -- 2.7.4