+2017-12-06 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/83075
+ * tree-ssa-strlen.c (handle_builtin_stxncpy): Avoid assuming
+ strncat/strncpy don't change length of source string.
+
2017-12-06 Eric Botcazou <ebotcazou@adacore.com>
Revert
+2017-12-06 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/83075
+ * gcc.dg/tree-ssa/strncat.c: New test.
+ * gcc.dg/tree-ssa/strncpy-2.c: Same.
+
2017-12-06 Bin Cheng <bin.cheng@arm.com>
* g++.dg/graphite/pr41305.C: Refine test option.
--- /dev/null
+/* PR tree-optimization/83075 - Invalid strncpy optimization
+ { dg-do run }
+ { dg-options "-O2 -Wno-stringop-overflow" } */
+
+int main (void)
+{
+ char a[8] = "";
+
+ __builtin_strcpy (a, "123");
+
+ unsigned n0 = __builtin_strlen (a);
+
+ __builtin_strncat (a + 3, a, n0);
+
+ unsigned n1 = __builtin_strlen (a);
+
+ if (n1 == n0)
+ __builtin_abort ();
+}
--- /dev/null
+/* PR tree-optimization/83075 - Invalid strncpy optimization
+ { dg-do run }
+ { dg-options "-O2 -Wno-stringop-overflow" } */
+
+int main (void)
+{
+ char a[8] = "";
+
+ __builtin_strcpy (a, "123");
+
+ unsigned n0 = __builtin_strlen (a);
+
+ __builtin_strncpy (a + 3, a, n0);
+
+ unsigned n1 = __builtin_strlen (a);
+
+ if (n1 == n0)
+ __builtin_abort ();
+}
int sidx = get_stridx (src);
strinfo *sisrc = sidx > 0 ? get_strinfo (sidx) : NULL;
- /* Strncpy() et al. cannot modify the source string. Prevent the rest
- of the pass from invalidating the strinfo data. */
- if (sisrc)
- sisrc->dont_invalidate = true;
+ /* strncat() and strncpy() can modify the source string by writing
+ over the terminating nul so SISRC->DONT_INVALIDATE must be left
+ clear. */
/* Retrieve the strinfo data for the string S that LEN was computed
from as some function F of strlen (S) (i.e., LEN need not be equal