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 d9c45c9e794927841357b25bd9526478bd4e567b..461656b1fa0843a5a8fed843c5ce9826333c3bf3 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 6d451959f1292a18c395d4adc6b6179b191ae19f..92e9e34ae07cfb79cca047abdff88eb55a8c894f 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 f0f6535017b1758a516f60ce4d4b3f8ad68708c6..94ed2bedc03958ddaf919a60e8cd9023a18f7f91 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);