aboutsummaryrefslogtreecommitdiff
path: root/gdb/valarith.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2020-11-15 03:18:35 -0500
committerJoel Brobecker <brobecker@adacore.com>2020-11-15 03:18:35 -0500
commitb74dbc2093191b10f4963f43ee570b54c9593404 (patch)
tree32f600bc82951ac58ec59e2142f7140174098208 /gdb/valarith.c
parent0a12719e51c456a5220f75950ebf9c07457c753b (diff)
downloadgdb-b74dbc2093191b10f4963f43ee570b54c9593404.zip
gdb-b74dbc2093191b10f4963f43ee570b54c9593404.tar.gz
gdb-b74dbc2093191b10f4963f43ee570b54c9593404.tar.bz2
Add support for fixed-point type comparison operators
This patch adds support for binary comparison operators with fixed-point type values. gdb/ChangeLog: * valarith.c (fixed_point_binop): Add BINOP_EQUAL and BINOP_LESS handling. (value_less): Add fixed-point handling. gdb/testsuite/ChangeLog: * gdb.ada/fixed_cmp.exp: Add -fgnat-encodings=minimal testing. * gdb.dwarf2/dw2-fixed-point.c (pck__fp1_var2): New global. (main): Add reference to pck__fp1_var2. * gdb.dwarf2/dw2-fixed-point.exp: Add comparison operator testing.
Diffstat (limited to 'gdb/valarith.c')
-rw-r--r--gdb/valarith.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 65a6f13..f4497cd 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -890,7 +890,9 @@ fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
{
struct type *type1 = check_typedef (value_type (arg1));
struct type *type2 = check_typedef (value_type (arg2));
+ const struct language_defn *language = current_language;
+ struct gdbarch *gdbarch = get_type_arch (type1);
struct value *val;
gdb_assert (is_fixed_point_type (type1) || is_fixed_point_type (type2));
@@ -952,6 +954,16 @@ fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
INIT_VAL_WITH_FIXED_POINT_VAL (res);
break;
+ case BINOP_EQUAL:
+ val = value_from_ulongest (language_bool_type (language, gdbarch),
+ mpq_cmp (v1.val, v2.val) == 0 ? 1 : 0);
+ break;
+
+ case BINOP_LESS:
+ val = value_from_ulongest (language_bool_type (language, gdbarch),
+ mpq_cmp (v1.val, v2.val) < 0 ? 1 : 0);
+ break;
+
default:
error (_("Integer-only operation on fixed point number."));
}
@@ -1774,7 +1786,8 @@ value_less (struct value *arg1, struct value *arg2)
is_int1 = is_integral_type (type1);
is_int2 = is_integral_type (type2);
- if (is_int1 && is_int2)
+ 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)));
else if ((is_floating_value (arg1) || is_int1)