https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127966
--- Comment #2 from Drea Pinski <pinskia at gcc dot gnu.org> ---
I think the problem is here: tree-ssa-loop-niter.cc:3738 :
/* iv.base can be &"Foo" but also (char *)&"Foo" + 1. */
split_constant_offset (iv.base, &str, &off);
STRIP_NOPS (str);
if (TREE_CODE (str) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (str, 0)) == STRING_CST
&& tree_fits_uhwi_p (off))
{
str = TREE_OPERAND (str, 0);
unsigned i = 0;
for (unsigned HOST_WIDE_INT idx
= (tree_to_uhwi (TREE_OPERAND (mem, 1))
+ tree_to_uhwi (off));
idx < (unsigned)TREE_STRING_LENGTH (str)
&& i < MAX_ITERATIONS_TO_TRACK;
idx += tree_to_uhwi (iv.step), ++i)
{
int res = compare_tree_int
(op[1], TREE_STRING_POINTER (str)[idx]);
if ((cmp == NE_EXPR && res == 0)
|| (cmp == EQ_EXPR && res != 0))
return build_int_cst (unsigned_type_node, i);
}
}
Which does not take into account the different types for the MEM_REF vs
STRING_CST.