[6/8] Use value_true in value_equal and value_less

Message ID 20230303211207.1053037-7-tromey@adacore.com
State New
Headers
Series Arithmetic for 128-bit types |

Commit Message

Tom Tromey March 3, 2023, 9:12 p.m. UTC
  Both value_equal and value_less use value_as_long to check a
presumably boolean result of calling value_binop.  However,
value_binop in this case actually returns an int as wide as its
arguments, and this approach can then fail for integers wider than
LONGEST.  Instead, rewrite this in a form that works for any size
integer.
---
 gdb/valarith.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
  

Patch

diff --git a/gdb/valarith.c b/gdb/valarith.c
index 9d681dc9d97..99597bef695 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -1761,8 +1761,7 @@  value_equal (struct value *arg1, struct value *arg2)
   is_int2 = is_integral_type (type2);
 
   if (is_int1 && is_int2)
-    return longest_to_int (value_as_long (value_binop (arg1, arg2,
-						       BINOP_EQUAL)));
+    return value_true (value_binop (arg1, arg2, BINOP_EQUAL));
   else if ((is_floating_value (arg1) || is_int1)
 	   && (is_floating_value (arg2) || is_int2))
     {
@@ -1849,8 +1848,7 @@  value_less (struct value *arg1, struct value *arg2)
 
   if ((is_int1 && is_int2)
       || (is_fixed_point_type (type1) && is_fixed_point_type (type2)))
-    return longest_to_int (value_as_long (value_binop (arg1, arg2,
-						       BINOP_LESS)));
+    return value_true (value_binop (arg1, arg2, BINOP_LESS));
   else if ((is_floating_value (arg1) || is_int1)
 	   && (is_floating_value (arg2) || is_int2))
     {