re PR tree-optimization/84383 (ICE in maybe_diag_stxncpy_trunc)
authorJakub Jelinek <jakub@redhat.com>
Thu, 15 Feb 2018 11:18:47 +0000 (12:18 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 15 Feb 2018 11:18:47 +0000 (12:18 +0100)
PR tree-optimization/84383
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Don't look at
dstoff nor call operand_equal_p if dstbase is NULL.

* gcc.c-torture/compile/pr84383.c: New test.

From-SVN: r257684

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

index 05b77100138a1242b88c9c1273ccc0252cbbdbb7..2768ada22b7cb7ce6aa6e8c318ff969d5ecd9aa7 100644 (file)
@@ -1,5 +1,9 @@
 2018-02-15  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/84383
+       * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Don't look at
+       dstoff nor call operand_equal_p if dstbase is NULL.
+
        PR tree-optimization/84334
        * match.pd ((A +- CST1) +- CST2 -> A + CST3): If A is
        also a CONSTANT_CLASS_P, punt.
index 2ac6e7b0dfa5665d8a880f4786a3b11fa8319e7f..c9f53d80b687f830c4f3be445a12946eb42e0d52 100644 (file)
@@ -1,5 +1,8 @@
 2018-02-15  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/84383
+       * gcc.c-torture/compile/pr84383.c: New test.
+
        PR tree-optimization/84334
        * gcc.dg/pr84334.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr84383.c b/gcc/testsuite/gcc.c-torture/compile/pr84383.c
new file mode 100644 (file)
index 0000000..b46f781
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR tree-optimization/84383 */
+
+struct S { char *s; };
+void bar (struct S *);
+
+void
+foo (int a, char *b)
+{
+  struct S c[4];
+  bar (c);
+  __builtin_strncpy (c[a].s, b, 32);
+  c[a].s[31] = '\0';
+  bar (c);
+}
index 94ed2bedc03958ddaf919a60e8cd9023a18f7f91..09ffa154439d02dfb607eccddc03e4c1d28a262d 100644 (file)
@@ -1878,6 +1878,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt)
       poly_int64 lhsoff;
       tree lhsbase = get_addr_base_and_unit_offset (lhs, &lhsoff);
       if (lhsbase
+         && dstbase
          && known_eq (dstoff, lhsoff)
          && operand_equal_p (dstbase, lhsbase, 0))
        return false;