OSDN Git Service

* integrate.c (compare_blocks): Make comparisons safe for when
authordj <dj@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 12 Apr 2002 18:37:56 +0000 (18:37 +0000)
committerdj <dj@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 12 Apr 2002 18:37:56 +0000 (18:37 +0000)
sizeof(int) < sizeof(char *).
(find_block): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@52232 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/integrate.c

index e875ba8..e5d336f 100644 (file)
@@ -1,3 +1,9 @@
+2002-04-12  DJ Delorie  <dj@redhat.com>
+
+       * integrate.c (compare_blocks): Make comparisons safe for when
+       sizeof(int) < sizeof(char *).
+       (find_block): Likewise.
+
 2002-04-12  Jan Hubicka  <jh@suse.cz>
            David Edelsohn  <edelsohn@gnu.org>
 
index 96366e3..3537364 100644 (file)
@@ -595,7 +595,8 @@ process_reg_param (map, loc, copy)
 }
 
 /* Compare two BLOCKs for qsort.  The key we sort on is the
-   BLOCK_ABSTRACT_ORIGIN of the blocks.  */
+   BLOCK_ABSTRACT_ORIGIN of the blocks.  We cannot just subtract the
+   two pointers, because it may overflow sizeof(int).  */
 
 static int
 compare_blocks (v1, v2)
@@ -604,9 +605,12 @@ compare_blocks (v1, v2)
 {
   tree b1 = *((const tree *) v1);
   tree b2 = *((const tree *) v2);
+  char *p1 = (char *) BLOCK_ABSTRACT_ORIGIN (b1);
+  char *p2 = (char *) BLOCK_ABSTRACT_ORIGIN (b2);
 
-  return ((char *) BLOCK_ABSTRACT_ORIGIN (b1)
-         - (char *) BLOCK_ABSTRACT_ORIGIN (b2));
+  if (p1 == p2)
+    return 0;
+  return p1 < p2 ? -1 : 1;
 }
 
 /* Compare two BLOCKs for bsearch.  The first pointer corresponds to
@@ -619,8 +623,12 @@ find_block (v1, v2)
 {
   const union tree_node *b1 = (const union tree_node *) v1;
   tree b2 = *((const tree *) v2);
+  char *p1 = (char *) b1;
+  char *p2 = (char *) BLOCK_ABSTRACT_ORIGIN (b2);
 
-  return ((const char *) b1 - (char *) BLOCK_ABSTRACT_ORIGIN (b2));
+  if (p1 == p2)
+    return 0;
+  return p1 < p2 ? -1 : 1;
 }
 
 /* Integrate the procedure defined by FNDECL.  Note that this function