[PATCH] Fix two spots with undefined behavior

Jakub Jelinek jakub@redhat.com
Tue Mar 25 07:13:00 GMT 2014


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?

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



More information about the Gcc-patches mailing list