re PR tree-optimization/84238 (ICE tree check: expected integer_cst, have plus_expr...
authorMarek Polacek <polacek@redhat.com>
Thu, 8 Feb 2018 16:18:04 +0000 (16:18 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 8 Feb 2018 16:18:04 +0000 (16:18 +0000)
PR tree-optimization/84238
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Verify the result of
get_range_strlen.

* gcc.dg/Wstringop-overflow-3.c: New test.

From-SVN: r257497

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wstringop-overflow-3.c [new file with mode: 0644]
gcc/tree-ssa-strlen.c

index d9c45c9..461656b 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-08  Marek Polacek  <polacek@redhat.com>
+
+       PR tree-optimization/84238
+       * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Verify the result of
+       get_range_strlen.
+
 2018-02-08  Richard Sandiford  <richard.sandiford@linaro.org>
 
        PR tree-optimization/84265
index 6d45195..92e9e34 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-08  Marek Polacek  <polacek@redhat.com>
+
+       PR tree-optimization/84238
+       * gcc.dg/Wstringop-overflow-3.c: New test.
+
 2018-02-08  Nathan Sidwell  <nathan@acm.org>
 
        * g++.dg/cpp0x/initlist93.C: Adjust diagnostic.
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-3.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-3.c
new file mode 100644 (file)
index 0000000..5901844
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR tree-optimization/84238 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+char a[1];
+int b;
+char *strncpy (char *, char *, __SIZE_TYPE__);
+void
+c ()
+{
+  char d[b];
+  strncpy (a, &d[3], 3); /* { dg-warning "writing 3 bytes into a region of size 1" } */
+}
index f0f6535..94ed2be 100644 (file)
@@ -1899,7 +1899,10 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt)
     {
       tree range[2];
       get_range_strlen (src, range);
-      if (range[0])
+      if (range[0] != NULL_TREE
+         && TREE_CODE (range[0]) == INTEGER_CST
+         && range[1] != NULL_TREE
+         && TREE_CODE (range[1]) == INTEGER_CST)
        {
          lenrange[0] = wi::to_wide (range[0], prec);
          lenrange[1] = wi::to_wide (range[1], prec);