This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix two spots with undefined behavior
- 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, 25 Mar 2014 10:05:28 +0100 (CET)
- Subject: Re: [PATCH] Fix two spots with undefined behavior
- Authentication-results: sourceware.org; auth=none
- References: <20140325070910 dot GI1817 at tucnak dot redhat dot com>
On Tue, 25 Mar 2014, Jakub Jelinek wrote:
> Hi!
>
> These two spots were determined by --with-build-config=bootstrap-ubsan
> as having undefined signed integer overflow.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for trunk?
Ok.
Thanks,
Richard.
> 2014-03-25 Jakub Jelinek <jakub@redhat.com>
>
> * cselib.c (cselib_hash_rtx): Perform addition in unsigned
> type to avoid signed integer overflow.
> * explow.c (plus_constant): Likewise.
>
> --- gcc/cselib.c.jj 2014-03-12 10:13:41.000000000 +0100
> +++ gcc/cselib.c 2014-03-22 08:30:21.622829993 +0100
> @@ -1137,7 +1137,7 @@ cselib_hash_rtx (rtx x, int create, enum
> return hash ? hash : (unsigned int) ENTRY_VALUE;
>
> case CONST_INT:
> - hash += ((unsigned) CONST_INT << 7) + INTVAL (x);
> + hash += ((unsigned) CONST_INT << 7) + UINTVAL (x);
> return hash ? hash : (unsigned int) CONST_INT;
>
> case CONST_DOUBLE:
> --- gcc/explow.c.jj 2014-01-03 11:40:57.000000000 +0100
> +++ gcc/explow.c 2014-03-22 08:31:42.379409989 +0100
> @@ -110,7 +110,7 @@ plus_constant (enum machine_mode mode, r
> return immed_double_int_const (v, mode);
> }
>
> - return gen_int_mode (INTVAL (x) + c, mode);
> + return gen_int_mode (UINTVAL (x) + c, mode);
>
> case CONST_DOUBLE:
> {
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer