re PR tree-optimization/88693 (Wrong code since r263018)
authorJakub Jelinek <jakub@redhat.com>
Fri, 11 Jan 2019 19:04:32 +0000 (20:04 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 11 Jan 2019 19:04:32 +0000 (20:04 +0100)
PR tree-optimization/88693
* tree-ssa-strlen.c (get_min_string_length): Don't set *full_string_p
for STRING_CSTs that don't contain any NUL characters in the first
TREE_STRING_LENGTH bytes.

* gcc.c-torture/execute/pr88693.c: New test.

From-SVN: r267852

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr88693.c [new file with mode: 0644]
gcc/tree-ssa-strlen.c

index cab2430e1f900e60673e68ba39a2410c7e2aff15..bca96c04ac81479f1b4927960d3659fbc04d38b3 100644 (file)
@@ -1,3 +1,10 @@
+2019-01-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/88693
+       * tree-ssa-strlen.c (get_min_string_length): Don't set *full_string_p
+       for STRING_CSTs that don't contain any NUL characters in the first
+       TREE_STRING_LENGTH bytes.
+
 2019-01-11  Alan Modra  <amodra@gmail.com>
 
        PR 88777
index 6baaa8e4afcef58532eca2ffc392e8267cb310e5..3b1de48f99020f07b1ba7b62350e149d229cd728 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/88693
+       * gcc.c-torture/execute/pr88693.c: New test.
+
 2019-01-11  Tamar Christina  <tamar.christina@arm.com>
 
        * gcc.target/aarch64/advsimd-intrinsics/vector-complex_f16.c: Require neon
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr88693.c b/gcc/testsuite/gcc.c-torture/execute/pr88693.c
new file mode 100644 (file)
index 0000000..7e78aea
--- /dev/null
@@ -0,0 +1,54 @@
+/* PR tree-optimization/88693 */
+
+__attribute__((noipa)) void
+foo (char *p)
+{
+  if (__builtin_strlen (p) != 9)
+    __builtin_abort ();
+}
+
+__attribute__((noipa)) void
+quux (char *p)
+{
+  int i;
+  for (i = 0; i < 100; i++)
+    if (p[i] != 'x')
+      __builtin_abort ();
+}
+
+__attribute__((noipa)) void
+qux (void)
+{
+  char b[100];
+  __builtin_memset (b, 'x', sizeof (b));
+  quux (b);
+}
+
+__attribute__((noipa)) void
+bar (void)
+{
+  static unsigned char u[9] = "abcdefghi";
+  char b[100];
+  __builtin_memcpy (b, u, sizeof (u));
+  b[sizeof (u)] = 0;
+  foo (b);
+}
+
+__attribute__((noipa)) void
+baz (void)
+{
+  static unsigned char u[] = { 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r' };
+  char b[100];
+  __builtin_memcpy (b, u, sizeof (u));
+  b[sizeof (u)] = 0;
+  foo (b);
+}
+
+int
+main ()
+{
+  qux ();
+  bar ();
+  baz ();
+  return 0;
+}
index 55fba88e0f4f7377735d54bb6a79388c90435f15..02ed1b4c77783ed969a9a0e9eabc88e659b356f6 100644 (file)
@@ -3232,8 +3232,9 @@ get_min_string_length (tree rhs, bool *full_string_p)
 
   if (rhs && TREE_CODE (rhs) == STRING_CST)
     {
-      *full_string_p = true;
-      return strlen (TREE_STRING_POINTER (rhs));
+      HOST_WIDE_INT len = strlen (TREE_STRING_POINTER (rhs));
+      *full_string_p = len < TREE_STRING_LENGTH (rhs);
+      return len;
     }
 
   return -1;