On Tue, Apr 24, 2018 at 2:53 PM, Jakub Jelinek <ja...@redhat.com> wrote:
> Hi!
>
> WHen INTVAL (x) is negative, this invokes UB, because left shift of negative
> value is undefined in C++.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK.

Richard.

> 2018-04-24  Jakub Jelinek  <ja...@redhat.com>
>
>         PR target/85508
>         * config/i386/i386.c (ix86_expand_vector_init_one_var): Use UINTVAL
>         instead of INTVAL when shifting x left.
>
>         * gcc.target/i386/pr85508.c: New test.
>
> --- gcc/config/i386/i386.c.jj   2018-04-24 10:37:01.258882134 +0200
> +++ gcc/config/i386/i386.c      2018-04-24 11:37:29.002706293 +0200
> @@ -43200,7 +43200,7 @@ ix86_expand_vector_init_one_var (bool mm
>        else
>         {
>           var = convert_modes (HImode, QImode, var, true);
> -         x = gen_int_mode (INTVAL (x) << 8, HImode);
> +         x = gen_int_mode (UINTVAL (x) << 8, HImode);
>         }
>        if (x != const0_rtx)
>         var = expand_simple_binop (HImode, IOR, var, x, var,
> --- gcc/testsuite/gcc.target/i386/pr85508.c.jj  2018-04-24 11:37:48.890721003 
> +0200
> +++ gcc/testsuite/gcc.target/i386/pr85508.c     2018-04-24 11:32:40.598491856 
> +0200
> @@ -0,0 +1,12 @@
> +/* PR target/85508 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -msse2" } */
> +
> +typedef signed char V __attribute__((vector_size (16)));
> +signed char c;
> +
> +V
> +foo (void)
> +{
> +  return (V) { c, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 
> };
> +}
>
>         Jakub

Reply via email to