fold-const.c (pointer_may_wrap_p): Call int_size_in_bytes rather than size_in_bytes.
authorIan Lance Taylor <iant@google.com>
Tue, 22 Apr 2008 21:23:23 +0000 (21:23 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 22 Apr 2008 21:23:23 +0000 (21:23 +0000)
./: * fold-const.c (pointer_may_wrap_p): Call int_size_in_bytes rather
than size_in_bytes.
testsuite/:
* gcc.c-torture/compile/20080419-1.c: New test.

From-SVN: r134566

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20080419-1.c [new file with mode: 0644]

index 761cf7ff99485bb5286741dab63dc250c602ecdb..6132b7fdd09516189512fb621feb53e0638d7c0e 100644 (file)
@@ -1,3 +1,8 @@
+2008-04-22  Ian Lance Taylor  <iant@google.com>
+
+       * fold-const.c (pointer_may_wrap_p): Call int_size_in_bytes rather
+       than size_in_bytes.
+
 2008-04-22  Pat Haugen  <pthaugen@us.ibm.com>
 
        * config/rs6000/rs6000.c (rs6000_register_move_cost): Increase cost
index f5ec30c17066d5deb2915ec0a8a8d9453fd81bd9..4015f62e5cd0425089c6d2b6afee81e3dedd9730 100644 (file)
@@ -8401,9 +8401,8 @@ maybe_canonicalize_comparison (enum tree_code code, tree type,
 static bool
 pointer_may_wrap_p (tree base, tree offset, HOST_WIDE_INT bitpos)
 {
-  tree size;
   unsigned HOST_WIDE_INT offset_low, total_low;
-  HOST_WIDE_INT offset_high, total_high;
+  HOST_WIDE_INT size, offset_high, total_high;
 
   if (!POINTER_TYPE_P (TREE_TYPE (base)))
     return true;
@@ -8411,21 +8410,6 @@ pointer_may_wrap_p (tree base, tree offset, HOST_WIDE_INT bitpos)
   if (bitpos < 0)
     return true;
 
-  size = size_in_bytes (TREE_TYPE (TREE_TYPE (base)));
-  if (size == NULL_TREE || TREE_CODE (size) != INTEGER_CST)
-    return true;
-
-  /* We can do slightly better for SIZE if we have an ADDR_EXPR of an
-     array.  */
-  if (TREE_CODE (base) == ADDR_EXPR)
-    {
-      tree base_size = size_in_bytes (TREE_TYPE (TREE_OPERAND (base, 0)));
-      if (base_size != NULL_TREE
-         && TREE_CODE (base_size) == INTEGER_CST
-         && INT_CST_LT_UNSIGNED (size, base_size))
-       size = base_size;
-    }
-
   if (offset == NULL_TREE)
     {
       offset_low = 0;
@@ -8445,13 +8429,25 @@ pointer_may_wrap_p (tree base, tree offset, HOST_WIDE_INT bitpos)
                            true))
     return true;
 
-  if ((unsigned HOST_WIDE_INT) total_high
-      < (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (size))
-    return false;
-  if ((unsigned HOST_WIDE_INT) total_high
-      > (unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (size))
+  if (total_high != 0)
     return true;
-  return total_low > TREE_INT_CST_LOW (size);
+
+  size = int_size_in_bytes (TREE_TYPE (TREE_TYPE (base)));
+  if (size <= 0)
+    return true;
+
+  /* We can do slightly better for SIZE if we have an ADDR_EXPR of an
+     array.  */
+  if (TREE_CODE (base) == ADDR_EXPR)
+    {
+      HOST_WIDE_INT base_size;
+
+      base_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (base, 0)));
+      if (base_size > 0 && size < base_size)
+       size = base_size;
+    }
+
+  return total_low > (unsigned HOST_WIDE_INT) size;
 }
 
 /* Subroutine of fold_binary.  This routine performs all of the
index cf06d4b0d1a296d8013fae5a63ef42d407fdfbe9..af0d3207a67793447fbaaf725600b9b0ec63b0f0 100644 (file)
@@ -1,3 +1,7 @@
+2008-04-22  Ian Lance Taylor  <iant@google.com>
+
+       * gcc.c-torture/compile/20080419-1.c: New test.
+
 2008-04-22  Kris Van Hees <kris.van.hees@oracle.com>
 
        PR testsuite/35981
diff --git a/gcc/testsuite/gcc.c-torture/compile/20080419-1.c b/gcc/testsuite/gcc.c-torture/compile/20080419-1.c
new file mode 100644 (file)
index 0000000..b257fea
--- /dev/null
@@ -0,0 +1,6 @@
+extern void *f();
+void dmi_scan_machine(void) {
+  char *p = f(), *q;
+  for (q = p; q < p + 10; q++)
+    ;
+}