[rfa/pascal!] Gag -Werror shift warning and bug

Andrew Cagney ac131313@cygnus.com
Fri Mar 2 17:58:00 GMT 2001


Hello,

The attatched gags a shift-overflow warning from GCC.  Thinking about
it, it also fixes a real bug!  The mn10200 has a 32 bit long-long and
that leads to the expression:

	1 << (32 - 32 - 1)

Outch!  Does my change look ok - I don't have a pascal compiler.

	Andrew
2001-03-02  Andrew Cagney  <ac131313@redhat.com>

	* p-exp.y (parse_number): Rearange computation of high_bit to
	avoid shift overflow from GCC.

Index: p-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/p-exp.y,v
retrieving revision 1.3
diff -p -r1.3 p-exp.y
*** p-exp.y	2000/12/01 20:05:48	1.3
--- p-exp.y	2001/03/03 01:53:03
*************** parse_number (p, len, parsed_float, puti
*** 858,871 ****
      }
    else
      {
!       high_bit = (((ULONGEST)1)
! 		  << (TARGET_LONG_LONG_BIT - 32 - 1)
! 		  << 16
! 		  << 16);
!       if (high_bit == 0)
  	/* A long long does not fit in a LONGEST.  */
  	high_bit =
  	  (ULONGEST)1 << (sizeof (LONGEST) * HOST_CHAR_BIT - 1);
        unsigned_type = builtin_type_unsigned_long_long;
        signed_type = builtin_type_long_long;
      }
--- 858,875 ----
      }
    else
      {
!       /* Assign to a variable to hide un-executed shift overflow from
!          GCC. */
!       int long_long_bit = TARGET_LONG_LONG_BIT;
!       if ((sizeof (ULONGEST) * HOST_CHAR_BIT) < long_long_bit)
  	/* A long long does not fit in a LONGEST.  */
  	high_bit =
  	  (ULONGEST)1 << (sizeof (LONGEST) * HOST_CHAR_BIT - 1);
+       else
+ 	high_bit = (((ULONGEST)1)
+ 		    << (long_long_bit - 32 - 1)
+ 		    << 16
+ 		    << 16);
        unsigned_type = builtin_type_unsigned_long_long;
        signed_type = builtin_type_long_long;
      }


More information about the Gdb-patches mailing list