This is the mail archive of the gcc-bugs@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]

Re: combine.c:1670: warning: left shift count >= width of type


On Feb 13, 2001, Andreas Jaeger <aj@suse.de> wrote:

> is your change to combine really correct?  On i686-linux I get now:

> /cvs/gcc/gcc/combine.c: In function `try_combine':
> /cvs/gcc/gcc/combine.c:1670: warning: left shift count >= width of type

It's definitely wrong.  I hadn't considered the possibility of
HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, and didn't notice the
warnings, and, out of (bad) luck, it would just work on x86.  Here's a
patch that fixes this problem.  Ok to install, if it completes
bootstrap?  Head and branch?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>
	* combine.c (UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD): New macro.
	(try_combine): Use it.

Index: gcc/combine.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/combine.c,v
retrieving revision 1.183
diff -u -p -r1.183 combine.c
--- gcc/combine.c 2001/02/06 12:39:15 1.183
+++ gcc/combine.c 2001/02/13 10:09:24
@@ -146,6 +146,12 @@ static int max_uid_cuid;
 #define INSN_CUID(INSN) \
 (INSN_UID (INSN) > max_uid_cuid ? insn_cuid (INSN) : uid_cuid[INSN_UID (INSN)])
 
+/* In case BITS_PER_WORD == HOST_BITS_PER_WIDE_INT, shifting by
+   BITS_PER_WORD would invoke undefined behavior.  Work around it.  */
+
+#define UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD(val) \
+  (((unsigned HOST_WIDE_INT)(val) << (BITS_PER_WORD - 1)) << 1)
+
 /* Maximum register number, which is the size of the tables below.  */
 
 static unsigned int combine_max_regno;
@@ -1667,7 +1673,7 @@ try_combine (i3, i2, i1, new_direct_jump
 	  if (HOST_BITS_PER_WIDE_INT < BITS_PER_WORD)
 	    abort ();
 
-	  lo &= ~(((unsigned HOST_WIDE_INT)1 << BITS_PER_WORD) - 1);
+	  lo &= ~(UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD (1) - 1);
 	  lo |= INTVAL (SET_SRC (PATTERN (i3)));
 	}
       else if (HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
@@ -1677,9 +1683,10 @@ try_combine (i3, i2, i1, new_direct_jump
 	  int sign = -(int) ((unsigned HOST_WIDE_INT) lo
 			     >> (HOST_BITS_PER_WIDE_INT - 1));
 
-	  lo &= ~((((unsigned HOST_WIDE_INT)1 << BITS_PER_WORD) - 1)
-		  << BITS_PER_WORD);
-	  lo |= INTVAL (SET_SRC (PATTERN (i3))) << BITS_PER_WORD;
+	  lo &= ~ (UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD
+		   (UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD (1) - 1));
+	  lo |= (UWIDE_SHIFT_LEFT_BY_BITS_PER_WORD
+		 (INTVAL (SET_SRC (PATTERN (i3)))));
 	  if (hi == sign)
 	    hi = lo < 0 ? -1 : 0;
 	}

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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