This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix UB in ix86_expand_vector_init_one_var (PR target/85508)
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Uros Bizjak <ubizjak at gmail dot com>, Kirill Yukhin <kirill dot yukhin at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 24 Apr 2018 15:12:15 +0200
- Subject: Re: [PATCH] Fix UB in ix86_expand_vector_init_one_var (PR target/85508)
- References: <20180424125327.GZ8577@tucnak>
On Tue, Apr 24, 2018 at 2:53 PM, Jakub Jelinek <jakub@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 <jakub@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