[PATCH] Fix fold-const comparisons with 0x7fffffffU

Jakub Jelinek jakub@redhat.com
Thu Mar 29 17:57:00 GMT 2001


Hi!

The testcase below fails on ia32 (but I guess any 32bit architecture) and is
a regression against 2.95.x.
gcc attempts to optimize (pointer type)x > (pointer type)0x7fffffff into
(signed pointer type)x < (signed pointer type)0, unfortunately signed_type()
returns the passed value for POINTER_TYPE_P, so it fails.
Ok to commit, provided pending bootstrap succeeds and there are no
regressions? Trunk and branch?

2001-03-29  Jakub Jelinek  <jakub@redhat.com>

	* fold-const.c (fold): Before optimizing unsigned comparison with
	0x7fffffffU, make sure arg0 is integral type.

	* gcc.c-torture/execute/20010329-1.c: New test.

--- gcc/fold-const.c.jj	Tue Mar 20 13:44:38 2001
+++ gcc/fold-const.c	Fri Mar 30 00:34:07 2001
@@ -6613,7 +6613,9 @@ fold (expr)
 	    else if (TREE_INT_CST_HIGH (arg1) == 0
 		      && (TREE_INT_CST_LOW (arg1)
 			  == ((unsigned HOST_WIDE_INT) 1 << (width - 1)) - 1)
-		      && TREE_UNSIGNED (TREE_TYPE (arg1)))
+		      && TREE_UNSIGNED (TREE_TYPE (arg1))
+			 /* signed_type does not work on pointer types.  */
+		      && INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
 
 	      switch (TREE_CODE (t))
 		{
--- gcc/testsuite/gcc.c-torture/execute/20010329-1.c.jj	Fri Mar 30 00:29:22 2001
+++ gcc/testsuite/gcc.c-torture/execute/20010329-1.c	Fri Mar 30 00:29:03 2001
@@ -0,0 +1,8 @@
+int main (void)
+{
+  void *x = ((void *)0x80000001);
+  if (x >= ((void *)0x80000000) && x <= ((void *)0x80000005))
+    exit (0);
+  else
+    abort ();
+}

	Jakub



More information about the Gcc-patches mailing list