https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94015
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|jakub at gcc dot gnu.org |msebor at gcc dot gnu.org --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- There's no need for two functions: their results couldn't be used with the current design. The problem is that handle_store treats the two MEM_REFs the same and the pass isn't set up to simultaneously track the lengths of two different things (a char* and char**) with the same SSA_NAME. A simple fix, when the storing a pointer as opposed to an array, is to just return the size of the pointer and not also the length of what it points to, like this: diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index b76b54efbd8..bf2a9d0c5d7 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -4697,9 +4697,17 @@ count_nonzero_bytes (tree exp, unsigned HOST_WIDE_INT offset, if (TREE_CODE (exp) == ADDR_EXPR) { /* If the size of the access hasn't been determined yet it's that - of a pointer. */ + of a pointer. In that case, ignore the lengths of what it points + to and simply return the range of lengths of its representation. */ if (!nbytes) - nbytes = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (exp))); + { + lenrange[0] = 0; + lenrange[1] = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (exp))); + lenrange[2] = lenrange[1]; + *allnul = false; + *nulterm = false; + return true; + } exp = TREE_OPERAND (exp, 0); }