From 1aad71067c3ed227a9fce0e50c1818250eef6f92 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Tue, 4 Jul 2017 11:48:44 +0000 Subject: PR 81292: ICE on related strlens after r249880 r249880 installed the result of a strlen in a strinfo if the strinfo wasn't previously a full string. But as Jakub says in the PR comments, we can't just do that in isolation, because there are no vdefs on the call that would invalidate any related strinfos. This patch updates the related strinfos if the adjustment is simple and invalidates them otherwise. As elsewhere, we treat adjustments of the form strlen +/- INTEGER_CST as simple but anything else as too complex. 2017-07-04 Richard Sandiford gcc/ PR tree-optimization/81292 * tree-ssa-strlen.c (handle_builtin_strlen): When setting full_string_p, also call adjust_related_strinfos if the adjustment is simple, otherwise invalidate related strinfos. gcc/testsuite/ PR tree-optimization/81292 * gcc.dg/pr81292-1.c: New test. * gcc.dg/pr81292-2.c: Likewise. From-SVN: r249961 --- gcc/tree-ssa-strlen.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'gcc/tree-ssa-strlen.c') diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 5118460..b0563fe 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -1214,8 +1214,23 @@ handle_builtin_strlen (gimple_stmt_iterator *gsi) /* Until now we only had a lower bound on the string length. Install LHS as the actual length. */ si = unshare_strinfo (si); + tree old = si->nonzero_chars; si->nonzero_chars = lhs; si->full_string_p = true; + if (TREE_CODE (old) == INTEGER_CST) + { + location_t loc = gimple_location (stmt); + old = fold_convert_loc (loc, TREE_TYPE (lhs), old); + tree adj = fold_build2_loc (loc, MINUS_EXPR, + TREE_TYPE (lhs), lhs, old); + adjust_related_strinfos (loc, si, adj); + } + else + { + si->first = 0; + si->prev = 0; + si->next = 0; + } } return; } -- cgit v1.1