On Mon, Aug 20, 2012 at 8:27 AM, Jakub Jelinek <ja...@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 <ja...@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