diff mbox

[1/6] tree-vrp: fix compare_assert_loc qsort comparator

Message ID 20170715204749.24398-2-amonakov@ispras.ru
State New
Headers show

Commit Message

Alexander Monakov July 15, 2017, 8:47 p.m. UTC
Subtracting values to produce a -/0/+ comparison value only works when
original values have limited range.  Otherwise it leads to broken
comparator that indicates 0 < 0x40000000 < 0x80000000 < 0.

Yuri posted an equivalent patch just a few hours ago:
https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00882.html

	* tree-vrp.c (compare_assert_loc): Properly compare hash values.
---
 gcc/tree-vrp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jeff Law July 19, 2017, 6:51 a.m. UTC | #1
On 07/15/2017 02:47 PM, Alexander Monakov wrote:
> Subtracting values to produce a -/0/+ comparison value only works when
> original values have limited range.  Otherwise it leads to broken
> comparator that indicates 0 < 0x40000000 < 0x80000000 < 0.
> 
> Yuri posted an equivalent patch just a few hours ago:
> https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00882.html
> 
> 	* tree-vrp.c (compare_assert_loc): Properly compare hash values.
Richi already ack'd Yuri's version, so let's stick with that.

jeff
diff mbox

Patch

diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 28205f1..d1888f6 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -6459,7 +6459,7 @@  compare_assert_loc (const void *pa, const void *pb)
     return (a->e != NULL
 	    ? a->e->src->index - b->e->src->index
 	    : a->bb->index - b->bb->index);
-  return ha - hb;
+  return ha < hb ? -1 : 1;
 }
 
 /* Process all the insertions registered for every name N_i registered