[patch] A preliminary fix for PR c/11449.

Kazu Hirata kazu@cs.umass.edu
Mon Jul 7 19:09:00 GMT 2003


Hi,

Attached is a patch to fix PR c/11449.

sign_bit_p (tree exp, tree val) in fold-const.c may return a wrong
result when

  TYPE_PRECISION (TREE_TYPE (exp)) == HOST_BITS_PER_WIDE_INT

In this case, the sign bit for TREE_TYPE (exp) is -2147483648,
assuming HOST_BITS_PER_WIDE_INT == 32.  If val is in fact -2147483648,
the function returns 0 because it expects the upper half of val to be
0 even though the upper half is actually -1 because of sign extension.

The patch fixes this problem by adding one more case in sign_bit_p,
width == HOST_BITS_PER_WIDE_INT, for a special handling.

I confirmed that this fixes PR c/11449.  OK to apply after regtesting?

Kazu Hirata

2003-07-07  Kazu Hirata  <kazu@cs.umass.edu>

	PR c/11449
	* fold-const.c (sign_bit_p): Return EXP if VAL is the sign bit
	of HOST_WIDE_INT.

2003-07-07  Kazu Hirata  <kazu@cs.umass.edu>

	PR c/11449
	* gcc.c-torture/compile/20030707-1.c: New.

Index: fold-const.c
===================================================================
RCS file: /home/kazu/nobackup/gcc-cvs/gcc/gcc/fold-const.c,v
retrieving revision 1.276
diff -u -r1.276 fold-const.c
--- fold-const.c	4 Jul 2003 22:00:19 -0000	1.276
+++ fold-const.c	7 Jul 2003 18:39:48 -0000
@@ -2740,6 +2740,11 @@
       hi = (unsigned HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT - 1);
       lo = 0;
     }
+  else if (width == HOST_BITS_PER_WIDE_INT)
+    {
+      hi = -1;
+      lo = (unsigned HOST_WIDE_INT) 1 << (width - 1);
+    }
   else
     {
       hi = 0;
--- /dev/null	2003-01-30 05:24:37.000000000 -0500
+++ 20030707-1.c	2003-07-07 15:06:06.000000000 -0400
@@ -0,0 +1,8 @@
+/* PR c/11449.  */
+
+int
+foo ()
+{
+  int m = 0;
+  return !(m & ((int) 0x80000000));
+}



More information about the Gcc-patches mailing list