]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR tree-optimization/88659 - ICE in maybe_warn_nonstring_arg
authorMartin Sebor <msebor@redhat.com>
Fri, 4 Jan 2019 03:13:33 +0000 (03:13 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Fri, 4 Jan 2019 03:13:33 +0000 (20:13 -0700)
gcc/ChangeLog:
* calls.c (maybe_warn_nonstring_arg): Avoid assuming maxlen is set.

gcc/testsuite/ChangeLog:
* gcc.dg/Wstringop-truncation-6.c: New test.

From-SVN: r267569

gcc/ChangeLog
gcc/calls.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wstringop-truncation-6.c [new file with mode: 0644]

index 5a15470c327e62ae30168ac41be4dd1e3ad54209..8715d3b69df7759449e1daba0d21c0eb1a3727c5 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-03  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/88659
+       * calls.c (maybe_warn_nonstring_arg): Avoid assuming maxlen is set.
+
 2019-01-03  Aaron Sawdey  <acsawdey@linux.ibm.com>
 
        * config/rs6000/rs6000-string.c (expand_block_move): Don't use
@@ -65,7 +70,7 @@
        (maybe_set_strlen_range): Parts refactored into set_strlen_range.
        Call set_strlen_range.
        * tree-ssa-strlen.h (set_strlen_range): Add prototype.
-       
+
        PR middle-end/88663
        * gimple-fold.c (get_range_strlen): Update prototype to no longer
        need the flexp argument.
@@ -80,7 +85,7 @@
        from get_range_strlen.
        * gimple-ssa-sprintf.c (get_string_length): Update for the new
        get_range_strlen API.
-       
+
 2019-01-02  Jan Hubicka  <hubicka@ucw.cz>
 
        PR lto/88130
index 04aafde99f6d81b41cd157b19fdbc198eb68d746..2e5d411f2174ed47ea5fac2c11e0e6c1acd09835 100644 (file)
@@ -1681,7 +1681,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
          bndrng[1] = maxlen;
          bound = void_type_node;
        }
-      else
+      else if (maxlen)
        {
          /* Replace the bound on the operation with the upper bound
             of the length of the string if the latter is smaller.  */
index ba9ed481c5f04d9a125c818c79b3913d4cf0da2b..1cfdfcd5b0415fc3dca3c2e49800a2f8b8d40fdf 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-03  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/88659
+       * gcc.dg/Wstringop-truncation-6.c: New test.
+
 2019-01-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/48543
diff --git a/gcc/testsuite/gcc.dg/Wstringop-truncation-6.c b/gcc/testsuite/gcc.dg/Wstringop-truncation-6.c
new file mode 100644 (file)
index 0000000..b58f291
--- /dev/null
@@ -0,0 +1,42 @@
+/* PR tree-optimization/88659 - ICE in maybe_warn_nonstring_arg
+   { dg-do compile }
+   { dg-options "-O0 -Wall" }  */
+
+const char a[5] = "1234";
+
+int cst_idx_cst_bnd (void)
+{
+  return __builtin_strnlen (&a[1], 0);
+}
+
+int var_idx_cst_bnd (void)
+{
+  int i = 1;
+  return __builtin_strnlen (&a[i], 0);
+}
+
+int phi_idx_cst_bnd (int i)
+{
+  return __builtin_strnlen (&a[i ? 1 : 2], 0);
+}
+
+int unk_idx_cst_bnd (int i)
+{
+  return __builtin_strnlen (&a[i], 0);
+}
+
+int cst_idx_var_bnd (void)
+{
+  int n = 0;
+  return __builtin_strnlen (&a[1], n);
+}
+
+int cst_idx_phi_bnd (int n)
+{
+  return __builtin_strnlen (&a[1], n ? 1 : 2);
+}
+
+int cst_idx_unk_bnd (int n)
+{
+  return __builtin_strnlen (&a[1], n);
+}