diff options
author | DJ Delorie <dj@redhat.com> | 2002-04-12 14:37:56 -0400 |
---|---|---|
committer | DJ Delorie <dj@gcc.gnu.org> | 2002-04-12 14:37:56 -0400 |
commit | 0339d2395be26ee053e1b4b4a277510cf5ea7d83 (patch) | |
tree | bd5de10339e68b2e6403476aec6541df3ae3916b /gcc/integrate.c | |
parent | cc4d5fec87941feae93ed070482e6c49a5ccf409 (diff) | |
download | gcc-0339d2395be26ee053e1b4b4a277510cf5ea7d83.zip gcc-0339d2395be26ee053e1b4b4a277510cf5ea7d83.tar.gz gcc-0339d2395be26ee053e1b4b4a277510cf5ea7d83.tar.bz2 |
integrate.c (compare_blocks): Make comparisons safe for when sizeof(int) < sizeof(char *).
* integrate.c (compare_blocks): Make comparisons safe for when
sizeof(int) < sizeof(char *).
(find_block): Likewise.
From-SVN: r52232
Diffstat (limited to 'gcc/integrate.c')
-rw-r--r-- | gcc/integrate.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/gcc/integrate.c b/gcc/integrate.c index 96366e3..3537364 100644 --- a/gcc/integrate.c +++ b/gcc/integrate.c @@ -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 |