This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix UB in round_up_loc (PR c/67338)
- From: Richard Biener <rguenther at suse dot de>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 21 Mar 2017 09:08:21 +0100 (CET)
- Subject: Re: [PATCH] Fix UB in round_up_loc (PR c/67338)
- Authentication-results: sourceware.org; auth=none
- References: <20170320210520.GM11094@tucnak>
On Mon, 20 Mar 2017, Jakub Jelinek wrote:
> Hi!
>
> divisor is unsigned int parameter, if it is 0x80000000, we invoke UB.
> val is wide_int, so (int) -divisor achieves the same result without UB.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Ok.
Thanks,
Richard.
> 2017-03-20 Jakub Jelinek <jakub@redhat.com>
>
> PR c/67338
> * fold-const.c (round_up_loc): Negate divisor in unsigned type to
> avoid UB.
>
> * gcc.dg/pr67338.c: New test.
>
> --- gcc/fold-const.c.jj 2017-03-16 17:18:25.000000000 +0100
> +++ gcc/fold-const.c 2017-03-20 07:53:53.680953740 +0100
> @@ -14250,7 +14250,7 @@ round_up_loc (location_t loc, tree value
>
> overflow_p = TREE_OVERFLOW (value);
> val += divisor - 1;
> - val &= - (int) divisor;
> + val &= (int) -divisor;
> if (val == 0)
> overflow_p = true;
>
> --- gcc/testsuite/gcc.dg/pr67338.c.jj 2017-03-20 09:09:05.489002468 +0100
> +++ gcc/testsuite/gcc.dg/pr67338.c 2017-03-20 09:08:54.000000000 +0100
> @@ -0,0 +1,4 @@
> +/* PR c/67338 */
> +/* { dg-do compile { target *-*-linux* *-*-gnu* } } */
> +
> +struct S { __attribute__((aligned (1 << 28))) double a; };
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)