+2018-01-26 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/83896
+ * tree-ssa-strlen.c (get_string_len): Rename...
+ (get_string_cst_length): ...to this. Return HOST_WIDE_INT.
+ Avoid assuming length is constant.
+ (handle_char_store): Use HOST_WIDE_INT for string length.
+
2018-01-26 Uros Bizjak <ubizjak@gmail.com>
PR target/81763
}
}
-/* Check if RHS is string_cst possibly wrapped by mem_ref. */
-static int
-get_string_len (tree rhs)
+/* If RHS, either directly or indirectly, refers to a string of constant
+ length, return it. Otherwise return a negative value. */
+
+static HOST_WIDE_INT
+get_string_cst_length (tree rhs)
{
if (TREE_CODE (rhs) == MEM_REF
&& integer_zerop (TREE_OPERAND (rhs, 1)))
{
- tree rhs_addr = rhs = TREE_OPERAND (rhs, 0);
+ rhs = TREE_OPERAND (rhs, 0);
if (TREE_CODE (rhs) == ADDR_EXPR)
{
+ tree rhs_addr = rhs;
+
rhs = TREE_OPERAND (rhs, 0);
if (TREE_CODE (rhs) != STRING_CST)
{
if (idx > 0)
{
strinfo *si = get_strinfo (idx);
- if (si && si->full_string_p)
+ if (si
+ && si->full_string_p
+ && tree_fits_shwi_p (si->nonzero_chars))
return tree_to_shwi (si->nonzero_chars);
}
}
rhs = DECL_INITIAL (rhs);
if (rhs && TREE_CODE (rhs) == STRING_CST)
- {
- unsigned HOST_WIDE_INT ilen = strlen (TREE_STRING_POINTER (rhs));
- return ilen <= INT_MAX ? ilen : -1;
- }
+ return strlen (TREE_STRING_POINTER (rhs));
return -1;
}
tree rhs = gimple_assign_rhs1 (stmt);
unsigned HOST_WIDE_INT offset = 0;
- /* Set to the length of the string being assigned if known. */
- int rhslen;
-
if (TREE_CODE (lhs) == MEM_REF
&& TREE_CODE (TREE_OPERAND (lhs, 0)) == SSA_NAME)
{
bool storing_nonzero_p = (!storing_zero_p
&& TREE_CODE (rhs) == INTEGER_CST
&& integer_nonzerop (rhs));
+ /* Set to the length of the string being assigned if known. */
+ HOST_WIDE_INT rhslen;
if (si != NULL)
{
}
}
else if (idx == 0
- && (rhslen = get_string_len (gimple_assign_rhs1 (stmt))) >= 0
+ && (rhslen = get_string_cst_length (gimple_assign_rhs1 (stmt))) >= 0
&& ssaname == NULL_TREE
&& TREE_CODE (TREE_TYPE (lhs)) == ARRAY_TYPE)
{