public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix loop pattern distribution ICE (PR tree-optimization/54321)
@ 2012-08-20  6:29 Jakub Jelinek
  2012-08-20  7:56 ` Richard Guenther
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2012-08-20  6:29 UTC (permalink / raw)
  To: gcc-patches

Hi!

The middle-end argument of memset is signed (int), so simplify_builtin_call
correctly checks host_integerp (val2, 0), but later on used tree_low_cst
(val2, 1), so for negative values it would ICE.  Fixed thusly, the memset
is supposed to cast the int to unsigned char internally anyway.

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

2012-08-20  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/54321
	* tree-ssa-forwprop.c (simplify_builtin_call): Pass 0 instead of 1
	as second argument to tree_low_cst call on val2.

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

--- gcc/tree-ssa-forwprop.c.jj	2012-08-14 08:45:00.000000000 +0200
+++ gcc/tree-ssa-forwprop.c	2012-08-20 08:11:06.247936035 +0200
@@ -1554,7 +1554,7 @@ simplify_builtin_call (gimple_stmt_itera
 	  else
 	    src_buf[0] = tree_low_cst (src1, 0);
 	  memset (src_buf + tree_low_cst (diff, 1),
-		  tree_low_cst (val2, 1), tree_low_cst (len2, 1));
+		  tree_low_cst (val2, 0), tree_low_cst (len2, 1));
 	  src_buf[src_len] = '\0';
 	  /* Neither builtin_strncpy_read_str nor builtin_memcpy_read_str
 	     handle embedded '\0's.  */
--- gcc/testsuite/gcc.c-torture/compile/pr54321.c.jj	2012-08-20 08:12:10.955630873 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr54321.c	2012-08-20 08:13:27.963398948 +0200
@@ -0,0 +1,12 @@
+/* PR tree-optimization/54321 */
+struct S { char s[0]; } *a;
+
+void
+foo (void)
+{
+  char *b = a->s;
+  int c = 0;
+  b[0] = 0;
+  while (++c < 9)
+    b[c] = 255;
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix loop pattern distribution ICE (PR tree-optimization/54321)
  2012-08-20  6:29 [PATCH] Fix loop pattern distribution ICE (PR tree-optimization/54321) Jakub Jelinek
@ 2012-08-20  7:56 ` Richard Guenther
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2012-08-20  7:56 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Mon, Aug 20, 2012 at 8:27 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> The middle-end argument of memset is signed (int), so simplify_builtin_call
> correctly checks host_integerp (val2, 0), but later on used tree_low_cst
> (val2, 1), so for negative values it would ICE.  Fixed thusly, the memset
> is supposed to cast the int to unsigned char internally anyway.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Yes, sorry for the mixup.

Thanks,
Richard.

> 2012-08-20  Jakub Jelinek  <jakub@redhat.com>
>
>         PR tree-optimization/54321
>         * tree-ssa-forwprop.c (simplify_builtin_call): Pass 0 instead of 1
>         as second argument to tree_low_cst call on val2.
>
>         * gcc.c-torture/compile/pr54321.c: New test.
>
> --- gcc/tree-ssa-forwprop.c.jj  2012-08-14 08:45:00.000000000 +0200
> +++ gcc/tree-ssa-forwprop.c     2012-08-20 08:11:06.247936035 +0200
> @@ -1554,7 +1554,7 @@ simplify_builtin_call (gimple_stmt_itera
>           else
>             src_buf[0] = tree_low_cst (src1, 0);
>           memset (src_buf + tree_low_cst (diff, 1),
> -                 tree_low_cst (val2, 1), tree_low_cst (len2, 1));
> +                 tree_low_cst (val2, 0), tree_low_cst (len2, 1));
>           src_buf[src_len] = '\0';
>           /* Neither builtin_strncpy_read_str nor builtin_memcpy_read_str
>              handle embedded '\0's.  */
> --- gcc/testsuite/gcc.c-torture/compile/pr54321.c.jj    2012-08-20 08:12:10.955630873 +0200
> +++ gcc/testsuite/gcc.c-torture/compile/pr54321.c       2012-08-20 08:13:27.963398948 +0200
> @@ -0,0 +1,12 @@
> +/* PR tree-optimization/54321 */
> +struct S { char s[0]; } *a;
> +
> +void
> +foo (void)
> +{
> +  char *b = a->s;
> +  int c = 0;
> +  b[0] = 0;
> +  while (++c < 9)
> +    b[c] = 255;
> +}
>
>         Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-20  7:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-20  6:29 [PATCH] Fix loop pattern distribution ICE (PR tree-optimization/54321) Jakub Jelinek
2012-08-20  7:56 ` Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).