From 44671f3f7f4c6435e7a639ad2215629f4e1ea8a7 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 24 Nov 2023 12:10:53 -0700 Subject: Allow cast of 128-bit integer to pointer PR rust/31082 points out that casting a 128-bit integer to a pointer will fail. This happens because a case in value_cast was not converted to use GMP. This patch fixes the problem. I am not really sure that testing against the negative value here makes sense, but I opted to just preserve the existing behavior rather than change it. Regression tested on x86-64 Fedora 38. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31082 --- gdb/valops.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'gdb/valops.c') diff --git a/gdb/valops.c b/gdb/valops.c index 6521580a1..b0e95c3 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -603,15 +603,13 @@ value_cast (struct type *type, struct value *arg2) pointers and four byte addresses. */ int addr_bit = gdbarch_addr_bit (type2->arch ()); - LONGEST longest = value_as_long (arg2); + gdb_mpz longest = value_as_mpz (arg2); - if (addr_bit < sizeof (LONGEST) * HOST_CHAR_BIT) - { - if (longest >= ((LONGEST) 1 << addr_bit) - || longest <= -((LONGEST) 1 << addr_bit)) - warning (_("value truncated")); - } - return value_from_longest (to_type, longest); + gdb_mpz addr_val = gdb_mpz (1) << addr_bit; + if (longest >= addr_val || longest <= -addr_val) + warning (_("value truncated")); + + return value_from_mpz (to_type, longest); } else if (code1 == TYPE_CODE_METHODPTR && code2 == TYPE_CODE_INT && value_as_long (arg2) == 0) -- cgit v1.1