[PATCH] Fix tree-ssa-strlen ICE introduced by r211956 (PR tree-optimization/61773)

2014-11-20 Thread Jakub Jelinek
Hi!

Before the r211956 changes, the only places that set si-stmt
were required to check that stpcpy has been declared (with the right
prototype) to signal the strlen pass that it can use stpcpy for
optimization.  But r211956 sets si-stmt also for malloca call,
which isn't in any way related to stpcpy.  So, this patch moves the
assertion where it really is needed (for strcat/strcpy and their checking
variants cases).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2014-11-20  Jakub Jelinek  ja...@redhat.com

PR tree-optimization/61773
* tree-ssa-strlen.c (get_string_length): Don't assert
stpcpy has been prototyped if si-stmt is BUILT_IN_MALLOC.

* gcc.dg/pr61773.c: New test.

--- gcc/tree-ssa-strlen.c.jj2014-11-19 18:47:59.0 +0100
+++ gcc/tree-ssa-strlen.c   2014-11-20 09:46:33.949017462 +0100
@@ -430,7 +430,6 @@ get_string_length (strinfo si)
   callee = gimple_call_fndecl (stmt);
   gcc_assert (callee  DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL);
   lhs = gimple_call_lhs (stmt);
-  gcc_assert (builtin_decl_implicit_p (BUILT_IN_STPCPY));
   /* unshare_strinfo is intentionally not called here.  The (delayed)
 transformation of strcpy or strcat into stpcpy is done at the place
 of the former strcpy/strcat call and so can affect all the strinfos
@@ -479,6 +478,7 @@ get_string_length (strinfo si)
case BUILT_IN_STRCPY_CHK:
case BUILT_IN_STRCPY_CHKP:
case BUILT_IN_STRCPY_CHK_CHKP:
+ gcc_assert (builtin_decl_implicit_p (BUILT_IN_STPCPY));
  if (gimple_call_num_args (stmt) == (with_bounds ? 4 : 2))
fn = builtin_decl_implicit (BUILT_IN_STPCPY);
  else
--- gcc/testsuite/gcc.dg/pr61773.c.jj   2014-11-20 10:12:48.664616764 +0100
+++ gcc/testsuite/gcc.dg/pr61773.c  2014-11-20 10:13:47.384557904 +0100
@@ -0,0 +1,16 @@
+/* PR tree-optimization/61773 */
+/* { dg-do compile } */
+/* { dg-options -O2 } */
+
+void
+foo (char **x)
+{
+  char *p = __builtin_malloc (64);
+  char *q = __builtin_malloc (64);
+  __builtin_strcat (q, abcde);
+  __builtin_strcat (p, ab);
+  p[1] = q[3];
+  __builtin_strcat (p, q);
+  x[0] = p;
+  x[1] = q;
+}

Jakub


Re: [PATCH] Fix tree-ssa-strlen ICE introduced by r211956 (PR tree-optimization/61773)

2014-11-20 Thread Richard Biener
On November 20, 2014 7:16:04 PM CET, Jakub Jelinek ja...@redhat.com wrote:
Hi!

Before the r211956 changes, the only places that set si-stmt
were required to check that stpcpy has been declared (with the right
prototype) to signal the strlen pass that it can use stpcpy for
optimization.  But r211956 sets si-stmt also for malloca call,
which isn't in any way related to stpcpy.  So, this patch moves the
assertion where it really is needed (for strcat/strcpy and their
checking
variants cases).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

2014-11-20  Jakub Jelinek  ja...@redhat.com

   PR tree-optimization/61773
   * tree-ssa-strlen.c (get_string_length): Don't assert
   stpcpy has been prototyped if si-stmt is BUILT_IN_MALLOC.

   * gcc.dg/pr61773.c: New test.

--- gcc/tree-ssa-strlen.c.jj   2014-11-19 18:47:59.0 +0100
+++ gcc/tree-ssa-strlen.c  2014-11-20 09:46:33.949017462 +0100
@@ -430,7 +430,6 @@ get_string_length (strinfo si)
   callee = gimple_call_fndecl (stmt);
gcc_assert (callee  DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL);
   lhs = gimple_call_lhs (stmt);
-  gcc_assert (builtin_decl_implicit_p (BUILT_IN_STPCPY));
/* unshare_strinfo is intentionally not called here.  The (delayed)
transformation of strcpy or strcat into stpcpy is done at the place
of the former strcpy/strcat call and so can affect all the strinfos
@@ -479,6 +478,7 @@ get_string_length (strinfo si)
   case BUILT_IN_STRCPY_CHK:
   case BUILT_IN_STRCPY_CHKP:
   case BUILT_IN_STRCPY_CHK_CHKP:
+gcc_assert (builtin_decl_implicit_p (BUILT_IN_STPCPY));
 if (gimple_call_num_args (stmt) == (with_bounds ? 4 : 2))
   fn = builtin_decl_implicit (BUILT_IN_STPCPY);
 else
--- gcc/testsuite/gcc.dg/pr61773.c.jj  2014-11-20 10:12:48.664616764
+0100
+++ gcc/testsuite/gcc.dg/pr61773.c 2014-11-20 10:13:47.384557904 +0100
@@ -0,0 +1,16 @@
+/* PR tree-optimization/61773 */
+/* { dg-do compile } */
+/* { dg-options -O2 } */
+
+void
+foo (char **x)
+{
+  char *p = __builtin_malloc (64);
+  char *q = __builtin_malloc (64);
+  __builtin_strcat (q, abcde);
+  __builtin_strcat (p, ab);
+  p[1] = q[3];
+  __builtin_strcat (p, q);
+  x[0] = p;
+  x[1] = q;
+}

   Jakub