From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 2A5353858D39; Tue, 9 Nov 2021 08:56:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A5353858D39 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5014] Convert strlen pass from evrp to ranger. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: cc6b8cd9a21b363815998b11e5cc7529557a9ce5 X-Git-Newrev: 6b8b959675a3e14cfdd2145bd62e4260eb193765 Message-Id: <20211109085623.2A5353858D39@sourceware.org> Date: Tue, 9 Nov 2021 08:56:23 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 08:56:23 -0000 https://gcc.gnu.org/g:6b8b959675a3e14cfdd2145bd62e4260eb193765 commit r12-5014-g6b8b959675a3e14cfdd2145bd62e4260eb193765 Author: Aldy Hernandez Date: Fri Oct 8 15:54:23 2021 +0200 Convert strlen pass from evrp to ranger. The following patch converts the strlen pass from evrp to ranger, leaving DOM as the last remaining user. No additional cleanups have been done. For example, the strlen pass still has uses of VR_ANTI_RANGE, and the sprintf still passes around pairs of integers instead of using a proper range. Fixing this could further improve these passes. Basically the entire patch is just adjusting the calls to range_of_expr to include context. The previous context of si->stmt was mostly empty, so not really useful ;-). With ranger we are now able to remove the range calculation from before_dom_children entirely. Just working with the ranger on-demand catches all the strlen and sprintf testcases with the exception of builtin-sprintf-warn-22.c which is due to a limitation of the sprintf code. I have XFAILed the test and documented what the problem is. On a positive note, these changes found two possible sprintf overflow bugs in the C++ and Fortran front-ends which I have fixed below. Tested on x86-64 Linux. gcc/ChangeLog: * tree-ssa-strlen.c (compare_nonzero_chars): Pass statement context to ranger. (get_addr_stridx): Same. (get_stridx): Same. (get_range_strlen_dynamic): Same. (handle_builtin_strlen): Same. (handle_builtin_strchr): Same. (handle_builtin_strcpy): Same. (maybe_diag_stxncpy_trunc): Same. (handle_builtin_stxncpy_strncat): Same. (handle_builtin_memcpy): Same. (handle_builtin_strcat): Same. (handle_alloc_call): Same. (handle_builtin_memset): Same. (handle_builtin_string_cmp): Same. (handle_pointer_plus): Same. (count_nonzero_bytes_addr): Same. (count_nonzero_bytes): Same. (handle_store): Same. (fold_strstr_to_strncmp): Same. (handle_integral_assign): Same. (check_and_optimize_stmt): Same. (class strlen_dom_walker): Replace evrp with ranger. (strlen_dom_walker::before_dom_children): Remove evrp. (strlen_dom_walker::after_dom_children): Remove evrp. * gimple-ssa-warn-access.cc (maybe_check_access_sizes): Restrict sprintf output. gcc/cp/ChangeLog: * ptree.c (cxx_print_xnode): Add more space to pfx array. gcc/fortran/ChangeLog: * misc.c (gfc_dummy_typename): Make sure ts->kind is non-negative. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/builtin-sprintf-warn-22.c: XFAIL. Diff: --- gcc/cp/ptree.c | 2 +- gcc/fortran/misc.c | 2 +- gcc/gimple-ssa-warn-access.cc | 2 +- .../gcc.dg/tree-ssa/builtin-sprintf-warn-22.c | 13 +- gcc/tree-ssa-strlen.c | 135 +++++++++++---------- 5 files changed, 85 insertions(+), 69 deletions(-) diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c index 1dcd764af01..ca7884db39b 100644 --- a/gcc/cp/ptree.c +++ b/gcc/cp/ptree.c @@ -292,7 +292,7 @@ cxx_print_xnode (FILE *file, tree node, int indent) for (unsigned ix = 0; ix != len; ix++) { binding_cluster *cluster = &BINDING_VECTOR_CLUSTER (node, ix); - char pfx[24]; + char pfx[32]; for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER; jx++) if (cluster->indices[jx].span) { diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c index e6402e881e3..a553e1ee6c5 100644 --- a/gcc/fortran/misc.c +++ b/gcc/fortran/misc.c @@ -284,7 +284,7 @@ gfc_dummy_typename (gfc_typespec *ts) { if (ts->kind == gfc_default_character_kind) sprintf(buffer, "CHARACTER(*)"); - else if (ts->kind < 10) + else if (ts->kind >= 0 && ts->kind < 10) sprintf(buffer, "CHARACTER(*,%d)", ts->kind); else sprintf(buffer, "CHARACTER(*,?)"); diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc index 63fc27a1487..073f122af31 100644 --- a/gcc/gimple-ssa-warn-access.cc +++ b/gcc/gimple-ssa-warn-access.cc @@ -3012,7 +3012,7 @@ pass_waccess::maybe_check_access_sizes (rdwr_map *rwm, tree fndecl, tree fntype, char *s1 = print_generic_expr_to_str (sizrng[1]); gcc_checking_assert (strlen (s0) + strlen (s1) < sizeof sizstr - 4); - sprintf (sizstr, "[%s, %s]", s0, s1); + sprintf (sizstr, "[%.37s, %.37s]", s0, s1); free (s1); } free (s0); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-22.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-22.c index 685a4fd8c89..82eb5851c59 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-22.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-22.c @@ -18,7 +18,18 @@ void g (char *s1, char *s2) if (n + d + 1 >= 1025) return; - sprintf (b, "%s.%s", s1, s2); // { dg-bogus "\\\[-Wformat-overflow" } + /* Ranger can find ranges here: + [1] n_6: size_t [0, 1023] + [2] d_8: size_t [0, 1023] + + Whereas evrp can't really: + [1] n_6: size_t [0, 9223372036854775805] + [2] d_8: size_t [0, 9223372036854775805] + + This is causing the sprintf warning pass to issue a false + positive here. */ + + sprintf (b, "%s.%s", s1, s2); // { dg-bogus "\\\[-Wformat-overflow" "" { xfail *-*-* } } f (b); } diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 2de7cb1a6a0..c0ec7d20a60 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -59,7 +59,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa-loop.h" #include "tree-scalar-evolution.h" #include "vr-values.h" -#include "gimple-ssa-evrp-analyze.h" +#include "gimple-range.h" #include "tree-ssa.h" /* A vector indexed by SSA_NAME_VERSION. 0 means unknown, positive value @@ -234,8 +234,7 @@ class strlen_pass : public dom_walker public: strlen_pass (cdi_direction direction) : dom_walker (direction), - evrp (false), - ptr_qry (&evrp, &var_cache), + ptr_qry (&m_ranger, &var_cache), var_cache (), m_cleanup_cfg (false) { @@ -277,15 +276,18 @@ public: unsigned HOST_WIDE_INT len[2], unsigned HOST_WIDE_INT *psize); bool count_nonzero_bytes (tree expr_or_type, + gimple *stmt, unsigned lenrange[3], bool *nulterm, bool *allnul, bool *allnonnul); bool count_nonzero_bytes (tree exp, + gimple *stmt, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT nbytes, unsigned lenrange[3], bool *nulterm, bool *allnul, bool *allnonnul, ssa_name_limit_t &snlim); bool count_nonzero_bytes_addr (tree exp, + gimple *stmt, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT nbytes, unsigned lenrange[3], bool *nulterm, @@ -295,9 +297,7 @@ public: unsigned HOST_WIDE_INT lenrng[2], unsigned HOST_WIDE_INT *size, bool *nulterm); - /* EVRP analyzer used for printf argument range processing, and to - track strlen results across integer variable assignments. */ - evrp_range_analyzer evrp; + gimple_ranger m_ranger; /* A pointer_query object and its cache to store information about pointers and their targets in. */ @@ -335,7 +335,8 @@ compare_nonzero_chars (strinfo *si, unsigned HOST_WIDE_INT off) Uses RVALS to determine length range. */ static int -compare_nonzero_chars (strinfo *si, unsigned HOST_WIDE_INT off, +compare_nonzero_chars (strinfo *si, gimple *stmt, + unsigned HOST_WIDE_INT off, range_query *rvals) { if (!si->nonzero_chars) @@ -348,7 +349,7 @@ compare_nonzero_chars (strinfo *si, unsigned HOST_WIDE_INT off, return -1; value_range vr; - if (!rvals->range_of_expr (vr, si->nonzero_chars, si->stmt)) + if (!rvals->range_of_expr (vr, si->nonzero_chars, stmt)) return -1; value_range_kind rng = vr.kind (); if (rng != VR_RANGE) @@ -403,7 +404,8 @@ get_next_strinfo (strinfo *si) information. */ static int -get_addr_stridx (tree exp, tree ptr, unsigned HOST_WIDE_INT *offset_out, +get_addr_stridx (tree exp, gimple *stmt, + tree ptr, unsigned HOST_WIDE_INT *offset_out, range_query *rvals = NULL) { HOST_WIDE_INT off; @@ -442,7 +444,7 @@ get_addr_stridx (tree exp, tree ptr, unsigned HOST_WIDE_INT *offset_out, unsigned HOST_WIDE_INT rel_off = (unsigned HOST_WIDE_INT) off - last->offset; strinfo *si = get_strinfo (last->idx); - if (si && compare_nonzero_chars (si, rel_off, rvals) >= 0) + if (si && compare_nonzero_chars (si, stmt, rel_off, rvals) >= 0) { if (offset_out) { @@ -464,7 +466,8 @@ get_addr_stridx (tree exp, tree ptr, unsigned HOST_WIDE_INT *offset_out, When nonnull, uses RVALS to determine range information. */ static int -get_stridx (tree exp, wide_int offrng[2] = NULL, range_query *rvals = NULL) +get_stridx (tree exp, gimple *stmt, + wide_int offrng[2] = NULL, range_query *rvals = NULL) { if (offrng) offrng[0] = offrng[1] = wi::zero (TYPE_PRECISION (ptrdiff_type_node)); @@ -601,7 +604,7 @@ get_stridx (tree exp, wide_int offrng[2] = NULL, range_query *rvals = NULL) if (TREE_CODE (exp) == ADDR_EXPR) { - int idx = get_addr_stridx (TREE_OPERAND (exp, 0), exp, NULL); + int idx = get_addr_stridx (TREE_OPERAND (exp, 0), stmt, exp, NULL); if (idx != 0) return idx; } @@ -1095,7 +1098,7 @@ get_range_strlen_dynamic (tree src, gimple *stmt, c_strlen_data *pdata, bitmap *visited, range_query *rvals, unsigned *pssa_def_max) { - int idx = get_stridx (src); + int idx = get_stridx (src, stmt); if (!idx) { if (TREE_CODE (src) == SSA_NAME) @@ -2200,7 +2203,7 @@ strlen_pass::handle_builtin_strlen () tree src = gimple_call_arg (stmt, 0); tree bound = (DECL_FUNCTION_CODE (callee) == BUILT_IN_STRNLEN ? gimple_call_arg (stmt, 1) : NULL_TREE); - int idx = get_stridx (src); + int idx = get_stridx (src, stmt); if (idx || (bound && integer_zerop (bound))) { strinfo *si = NULL; @@ -2380,7 +2383,7 @@ strlen_pass::handle_builtin_strchr () if (!check_nul_terminated_array (NULL_TREE, src)) return; - int idx = get_stridx (src); + int idx = get_stridx (src, stmt); if (idx) { strinfo *si = NULL; @@ -2486,12 +2489,12 @@ strlen_pass::handle_builtin_strcpy (built_in_function bcode) src = gimple_call_arg (stmt, 1); dst = gimple_call_arg (stmt, 0); lhs = gimple_call_lhs (stmt); - idx = get_stridx (src); + idx = get_stridx (src, stmt); si = NULL; if (idx > 0) si = get_strinfo (idx); - didx = get_stridx (dst); + didx = get_stridx (dst, stmt); olddsi = NULL; oldlen = NULL_TREE; if (didx > 0) @@ -2893,7 +2896,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt, when ssa_ver_to_stridx is empty. That implies the caller isn't running under the control of this pass and ssa_ver_to_stridx hasn't been created yet. */ - int sidx = ssa_ver_to_stridx.length () ? get_stridx (src) : 0; + int sidx = ssa_ver_to_stridx.length () ? get_stridx (src, stmt) : 0; if (sidx < 0 && wi::gtu_p (cntrange[0], ~sidx)) return false; @@ -3167,7 +3170,7 @@ strlen_pass::handle_builtin_stxncpy_strncat (bool append_p) a lower bound). */ tree dstlenp1 = NULL_TREE, srclenp1 = NULL_TREE;; - int didx = get_stridx (dst); + int didx = get_stridx (dst, stmt); if (strinfo *sidst = didx > 0 ? get_strinfo (didx) : NULL) { /* Compute the size of the destination string including the nul @@ -3193,7 +3196,7 @@ strlen_pass::handle_builtin_stxncpy_strncat (bool append_p) dst = sidst->ptr; } - int sidx = get_stridx (src); + int sidx = get_stridx (src, stmt); strinfo *sisrc = sidx > 0 ? get_strinfo (sidx) : NULL; if (sisrc) { @@ -3302,7 +3305,7 @@ strlen_pass::handle_builtin_memcpy (built_in_function bcode) tree src = gimple_call_arg (stmt, 1); tree dst = gimple_call_arg (stmt, 0); - int didx = get_stridx (dst); + int didx = get_stridx (dst, stmt); strinfo *olddsi = NULL; if (didx > 0) olddsi = get_strinfo (didx); @@ -3316,7 +3319,7 @@ strlen_pass::handle_builtin_memcpy (built_in_function bcode) adjust_last_stmt (olddsi, stmt, false); } - int idx = get_stridx (src); + int idx = get_stridx (src, stmt); if (idx == 0) return; @@ -3491,7 +3494,7 @@ strlen_pass::handle_builtin_strcat (built_in_function bcode) tree lhs = gimple_call_lhs (stmt); - didx = get_stridx (dst); + didx = get_stridx (dst, stmt); if (didx < 0) return; @@ -3501,7 +3504,7 @@ strlen_pass::handle_builtin_strcat (built_in_function bcode) srclen = NULL_TREE; si = NULL; - idx = get_stridx (src); + idx = get_stridx (src, stmt); if (idx < 0) srclen = build_int_cst (size_type_node, ~idx); else if (idx > 0) @@ -3723,7 +3726,7 @@ strlen_pass::handle_alloc_call (built_in_function bcode) if (lhs == NULL_TREE) return; - gcc_assert (get_stridx (lhs) == 0); + gcc_assert (get_stridx (lhs, stmt) == 0); int idx = new_stridx (lhs); tree length = NULL_TREE; if (bcode == BUILT_IN_CALLOC) @@ -3759,7 +3762,7 @@ strlen_pass::handle_builtin_memset (bool *zero_write) tree ptr = gimple_call_arg (memset_stmt, 0); /* Set to the non-constant offset added to PTR. */ wide_int offrng[2]; - int idx1 = get_stridx (ptr, offrng, ptr_qry.rvals); + int idx1 = get_stridx (ptr, memset_stmt, offrng, ptr_qry.rvals); if (idx1 <= 0) return false; strinfo *si1 = get_strinfo (idx1); @@ -4250,8 +4253,8 @@ strlen_pass::handle_builtin_string_cmp () tree arg1 = gimple_call_arg (stmt, 0); tree arg2 = gimple_call_arg (stmt, 1); - int idx1 = get_stridx (arg1); - int idx2 = get_stridx (arg2); + int idx1 = get_stridx (arg1, stmt); + int idx2 = get_stridx (arg2, stmt); /* For strncmp set to the value of the third argument if known. */ HOST_WIDE_INT bound = -1; @@ -4389,7 +4392,7 @@ strlen_pass::handle_pointer_plus () { gimple *stmt = gsi_stmt (m_gsi); tree lhs = gimple_assign_lhs (stmt), off; - int idx = get_stridx (gimple_assign_rhs1 (stmt)); + int idx = get_stridx (gimple_assign_rhs1 (stmt), stmt); strinfo *si, *zsi; if (idx == 0) @@ -4482,7 +4485,7 @@ nonzero_bytes_for_type (tree type, unsigned lenrange[3], Returns true on success and false otherwise. */ bool -strlen_pass::count_nonzero_bytes (tree exp, +strlen_pass::count_nonzero_bytes (tree exp, gimple *stmt, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT nbytes, unsigned lenrange[3], bool *nulterm, @@ -4502,7 +4505,8 @@ strlen_pass::count_nonzero_bytes (tree exp, exact value is not known) recurse once to set the range for an arbitrary constant. */ exp = build_int_cst (type, 1); - return count_nonzero_bytes (exp, offset, 1, lenrange, + return count_nonzero_bytes (exp, stmt, + offset, 1, lenrange, nulterm, allnul, allnonnul, snlim); } @@ -4529,7 +4533,8 @@ strlen_pass::count_nonzero_bytes (tree exp, for (unsigned i = 0; i != n; i++) { tree def = gimple_phi_arg_def (stmt, i); - if (!count_nonzero_bytes (def, offset, nbytes, lenrange, nulterm, + if (!count_nonzero_bytes (def, stmt, + offset, nbytes, lenrange, nulterm, allnul, allnonnul, snlim)) return false; } @@ -4586,7 +4591,8 @@ strlen_pass::count_nonzero_bytes (tree exp, return false; /* Handle MEM_REF = SSA_NAME types of assignments. */ - return count_nonzero_bytes_addr (arg, offset, nbytes, lenrange, nulterm, + return count_nonzero_bytes_addr (arg, stmt, + offset, nbytes, lenrange, nulterm, allnul, allnonnul, snlim); } @@ -4698,14 +4704,14 @@ strlen_pass::count_nonzero_bytes (tree exp, bytes that are pointed to by EXP, which should be a pointer. */ bool -strlen_pass::count_nonzero_bytes_addr (tree exp, +strlen_pass::count_nonzero_bytes_addr (tree exp, gimple *stmt, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT nbytes, unsigned lenrange[3], bool *nulterm, bool *allnul, bool *allnonnul, ssa_name_limit_t &snlim) { - int idx = get_stridx (exp); + int idx = get_stridx (exp, stmt); if (idx > 0) { strinfo *si = get_strinfo (idx); @@ -4721,7 +4727,7 @@ strlen_pass::count_nonzero_bytes_addr (tree exp, && TREE_CODE (si->nonzero_chars) == SSA_NAME) { value_range vr; - ptr_qry.rvals->range_of_expr (vr, si->nonzero_chars, si->stmt); + ptr_qry.rvals->range_of_expr (vr, si->nonzero_chars, stmt); if (vr.kind () != VR_RANGE) return false; @@ -4767,7 +4773,8 @@ strlen_pass::count_nonzero_bytes_addr (tree exp, } if (TREE_CODE (exp) == ADDR_EXPR) - return count_nonzero_bytes (TREE_OPERAND (exp, 0), offset, nbytes, + return count_nonzero_bytes (TREE_OPERAND (exp, 0), stmt, + offset, nbytes, lenrange, nulterm, allnul, allnonnul, snlim); if (TREE_CODE (exp) == SSA_NAME) @@ -4786,7 +4793,8 @@ strlen_pass::count_nonzero_bytes_addr (tree exp, for (unsigned i = 0; i != n; i++) { tree def = gimple_phi_arg_def (stmt, i); - if (!count_nonzero_bytes_addr (def, offset, nbytes, lenrange, + if (!count_nonzero_bytes_addr (def, stmt, + offset, nbytes, lenrange, nulterm, allnul, allnonnul, snlim)) return false; @@ -4814,7 +4822,7 @@ strlen_pass::count_nonzero_bytes_addr (tree exp, (the results of strlen). */ bool -strlen_pass::count_nonzero_bytes (tree expr_or_type, +strlen_pass::count_nonzero_bytes (tree expr_or_type, gimple *stmt, unsigned lenrange[3], bool *nulterm, bool *allnul, bool *allnonnul) { @@ -4833,7 +4841,8 @@ strlen_pass::count_nonzero_bytes (tree expr_or_type, ssa_name_limit_t snlim; tree expr = expr_or_type; - return count_nonzero_bytes (expr, 0, 0, lenrange, nulterm, allnul, allnonnul, + return count_nonzero_bytes (expr, stmt, + 0, 0, lenrange, nulterm, allnul, allnonnul, snlim); } @@ -4885,18 +4894,19 @@ strlen_pass::handle_store (bool *zero_write) least OFFSET nonzero characters. This is trivially true if OFFSET is zero. */ offset = tree_to_uhwi (mem_offset); - idx = get_stridx (TREE_OPERAND (lhs, 0)); + idx = get_stridx (TREE_OPERAND (lhs, 0), stmt); if (idx > 0) si = get_strinfo (idx); if (offset == 0) ssaname = TREE_OPERAND (lhs, 0); - else if (si == NULL || compare_nonzero_chars (si, offset, rvals) < 0) + else if (si == NULL + || compare_nonzero_chars (si, stmt, offset, rvals) < 0) { *zero_write = rhs ? initializer_zerop (rhs) : false; bool dummy; unsigned lenrange[] = { UINT_MAX, 0, 0 }; - if (count_nonzero_bytes (rhs ? rhs : storetype, lenrange, + if (count_nonzero_bytes (rhs ? rhs : storetype, stmt, lenrange, &dummy, &dummy, &dummy)) maybe_warn_overflow (stmt, true, lenrange[2]); @@ -4906,7 +4916,7 @@ strlen_pass::handle_store (bool *zero_write) } else { - idx = get_addr_stridx (lhs, NULL_TREE, &offset, rvals); + idx = get_addr_stridx (lhs, stmt, NULL_TREE, &offset, rvals); if (idx > 0) si = get_strinfo (idx); } @@ -4929,7 +4939,8 @@ strlen_pass::handle_store (bool *zero_write) bool full_string_p; const bool ranges_valid - = count_nonzero_bytes (rhs ? rhs : storetype, lenrange, &full_string_p, + = count_nonzero_bytes (rhs ? rhs : storetype, stmt, + lenrange, &full_string_p, &storing_all_zeros_p, &storing_all_nonzero_p); if (ranges_valid) @@ -4961,15 +4972,18 @@ strlen_pass::handle_store (bool *zero_write) { /* The offset of the last stored byte. */ unsigned HOST_WIDE_INT endoff = offset + lenrange[2] - 1; - store_before_nul[0] = compare_nonzero_chars (si, offset, rvals); + store_before_nul[0] + = compare_nonzero_chars (si, stmt, offset, rvals); if (endoff == offset) store_before_nul[1] = store_before_nul[0]; else - store_before_nul[1] = compare_nonzero_chars (si, endoff, rvals); + store_before_nul[1] + = compare_nonzero_chars (si, stmt, endoff, rvals); } else { - store_before_nul[0] = compare_nonzero_chars (si, offset, rvals); + store_before_nul[0] + = compare_nonzero_chars (si, stmt, offset, rvals); store_before_nul[1] = store_before_nul[0]; gcc_assert (offset == 0 || store_before_nul[0] >= 0); } @@ -5194,7 +5208,7 @@ fold_strstr_to_strncmp (tree rhs1, tree rhs2, gimple *stmt) { tree arg1 = gimple_call_arg (call_stmt, 1); tree arg1_len = NULL_TREE; - int idx = get_stridx (arg1); + int idx = get_stridx (arg1, call_stmt); if (idx) { @@ -5406,7 +5420,7 @@ strlen_pass::handle_integral_assign (bool *cleanup_eh) tree rhs1 = gimple_assign_rhs1 (stmt); if (code == MEM_REF) { - idx = get_stridx (TREE_OPERAND (rhs1, 0)); + idx = get_stridx (TREE_OPERAND (rhs1, 0), stmt); if (idx > 0) { strinfo *si = get_strinfo (idx); @@ -5423,7 +5437,7 @@ strlen_pass::handle_integral_assign (bool *cleanup_eh) } } if (idx <= 0) - idx = get_addr_stridx (rhs1, NULL_TREE, &coff); + idx = get_addr_stridx (rhs1, stmt, NULL_TREE, &coff); if (idx > 0) { strinfo *si = get_strinfo (idx); @@ -5485,7 +5499,8 @@ strlen_pass::handle_integral_assign (bool *cleanup_eh) unsigned lenrange[] = { UINT_MAX, 0, 0 }; tree rhs = gimple_assign_rhs1 (stmt); const bool ranges_valid - = count_nonzero_bytes (rhs, lenrange, &full_string_p, + = count_nonzero_bytes (rhs, stmt, + lenrange, &full_string_p, &storing_all_zeros_p, &storing_all_nonzero_p); if (ranges_valid) @@ -5582,7 +5597,7 @@ strlen_pass::check_and_optimize_stmt (bool *cleanup_eh) || (gimple_assign_cast_p (stmt) && POINTER_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (stmt))))) { - int idx = get_stridx (gimple_assign_rhs1 (stmt)); + int idx = get_stridx (gimple_assign_rhs1 (stmt), stmt); ssa_ver_to_stridx[SSA_NAME_VERSION (lhs)] = idx; } else if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR) @@ -5672,8 +5687,6 @@ strlen_pass::~strlen_pass () edge strlen_pass::before_dom_children (basic_block bb) { - evrp.enter (bb); - basic_block dombb = get_immediate_dominator (CDI_DOMINATORS, bb); if (dombb == NULL) @@ -5730,12 +5743,12 @@ strlen_pass::before_dom_children (basic_block bb) tree result = gimple_phi_result (phi); if (!virtual_operand_p (result) && POINTER_TYPE_P (TREE_TYPE (result))) { - int idx = get_stridx (gimple_phi_arg_def (phi, 0)); + int idx = get_stridx (gimple_phi_arg_def (phi, 0), phi); if (idx != 0) { unsigned int i, n = gimple_phi_num_args (phi); for (i = 1; i < n; i++) - if (idx != get_stridx (gimple_phi_arg_def (phi, i))) + if (idx != get_stridx (gimple_phi_arg_def (phi, i), phi)) break; if (i == n) ssa_ver_to_stridx[SSA_NAME_VERSION (result)] = idx; @@ -5748,12 +5761,6 @@ strlen_pass::before_dom_children (basic_block bb) /* Attempt to optimize individual statements. */ for (m_gsi = gsi_start_bb (bb); !gsi_end_p (m_gsi); ) { - gimple *stmt = gsi_stmt (m_gsi); - - /* First record ranges generated by this statement so they - can be used by printf argument processing. */ - evrp.record_ranges_from_stmt (stmt, false); - /* Reset search depth preformance counter. */ ptr_qry.depth = 0; @@ -5776,8 +5783,6 @@ strlen_pass::before_dom_children (basic_block bb) void strlen_pass::after_dom_children (basic_block bb) { - evrp.leave (bb); - if (bb->aux) { stridx_to_strinfo = ((vec *) bb->aux);