+2018-01-03 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
+
+ PR tree-optimization/83501
+ * tree-ssa-strlen.c (get_string_cst): New.
+ (handle_char_store): Call get_string_cst.
+
2018-01-03 Martin Liska <mliska@suse.cz>
PR tree-optimization/83593
+2018-01-03 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
+
+ PR tree-optimization/83501
+ * gcc.dg/tree-ssa/pr83501-1.c: New test.
+
2018-01-03 Nathan Sidwell <nathan@acm.org>
PR c++/83667
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-strlen" } */
+
+char a[4];
+
+void f (void)
+{
+ __builtin_strcpy (a, "abc");
+
+ if (__builtin_strlen (a) != 3)
+ __builtin_abort ();
+}
+
+/* { dg-final { scan-tree-dump-not "__builtin_strlen" "strlen" } } */
}
}
+/* Check if RHS is string_cst possibly wrapped by mem_ref. */
+static tree
+get_string_cst (tree rhs)
+{
+ if (TREE_CODE (rhs) == MEM_REF
+ && integer_zerop (TREE_OPERAND (rhs, 1)))
+ {
+ rhs = TREE_OPERAND (rhs, 0);
+ if (TREE_CODE (rhs) == ADDR_EXPR)
+ rhs = TREE_OPERAND (rhs, 0);
+ }
+
+ return (TREE_CODE (rhs) == STRING_CST) ? rhs : NULL_TREE;
+}
+
/* Handle a single character store. */
static bool
}
}
else if (idx == 0
- && TREE_CODE (gimple_assign_rhs1 (stmt)) == STRING_CST
+ && (rhs = get_string_cst (gimple_assign_rhs1 (stmt)))
&& ssaname == NULL_TREE
&& TREE_CODE (TREE_TYPE (lhs)) == ARRAY_TYPE)
{
- size_t l = strlen (TREE_STRING_POINTER (gimple_assign_rhs1 (stmt)));
+ size_t l = strlen (TREE_STRING_POINTER (rhs));
HOST_WIDE_INT a = int_size_in_bytes (TREE_TYPE (lhs));
if (a > 0 && (unsigned HOST_WIDE_INT) a > l)
{