This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix two spots with undefined behavior


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]