aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannes Domani <ssbssa@yahoo.de>2024-06-11 20:36:51 +0200
committerHannes Domani <ssbssa@yahoo.de>2024-06-11 20:36:51 +0200
commit3dd8c680a8651aa22c996b1e2d39dd123f204be3 (patch)
tree943239eef9cefd5c963e1055449b3d62968adc2c
parent50f4e9c3c3e5115b346f361de1374837c990f14b (diff)
downloadgdb-3dd8c680a8651aa22c996b1e2d39dd123f204be3.zip
gdb-3dd8c680a8651aa22c996b1e2d39dd123f204be3.tar.gz
gdb-3dd8c680a8651aa22c996b1e2d39dd123f204be3.tar.bz2
Fix 64-bit shifts where long only has 32-bit size
On systems where long has 32-bit size you get these failures: print 1 << (unsigned long long) 0xffffffffffffffff Cannot export value 18446744073709551615 as 32-bits unsigned integer (must be between 0 and 4294967295) (gdb) FAIL: gdb.base/bitshift.exp: lang=c: max-uint64: print 1 << (unsigned long long) 0xffffffffffffffff print 1 >> (unsigned long long) 0xffffffffffffffff Cannot export value 18446744073709551615 as 32-bits unsigned integer (must be between 0 and 4294967295) (gdb) FAIL: gdb.base/bitshift.exp: lang=c: max-uint64: print 1 >> (unsigned long long) 0xffffffffffffffff print -1 << (unsigned long long) 0xffffffffffffffff Cannot export value 18446744073709551615 as 32-bits unsigned integer (must be between 0 and 4294967295) (gdb) FAIL: gdb.base/bitshift.exp: lang=c: max-uint64: print -1 << (unsigned long long) 0xffffffffffffffff print -1 >> (unsigned long long) 0xffffffffffffffff Cannot export value 18446744073709551615 as 32-bits unsigned integer (must be between 0 and 4294967295) (gdb) FAIL: gdb.base/bitshift.exp: lang=c: max-uint64: print -1 >> (unsigned long long) 0xffffffffffffffff Fixed by changing the number-of-bits variable to ULONGEST. Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/testsuite/gdb.base/bitshift.exp12
-rw-r--r--gdb/valarith.c8
2 files changed, 16 insertions, 4 deletions
diff --git a/gdb/testsuite/gdb.base/bitshift.exp b/gdb/testsuite/gdb.base/bitshift.exp
index d6e2521..cab82e1 100644
--- a/gdb/testsuite/gdb.base/bitshift.exp
+++ b/gdb/testsuite/gdb.base/bitshift.exp
@@ -363,6 +363,18 @@ proc test_shifts {} {
test_rshift_tl $lang \
"print -1 >> [make_uint64 $lang 0xffffffffffffffff]" " = -1"
}
+
+ # Check if shift value isn't silently truncated to 32bit.
+ with_test_prefix "lower-32bit-zero" {
+ test_lshift_tl $lang \
+ "print 1 << [make_uint64 $lang 0x100000000]" " = 0"
+ test_rshift_tl $lang \
+ "print 1 >> [make_uint64 $lang 0x100000000]" " = 0"
+ test_lshift_tl $lang \
+ "print -1 << [make_uint64 $lang 0x100000000]" " = 0"
+ test_rshift_tl $lang \
+ "print -1 >> [make_uint64 $lang 0x100000000]" " = -1"
+ }
}
}
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 6160b0e..a95d108 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -1086,7 +1086,7 @@ type_length_bits (type *type)
static bool
check_valid_shift_count (enum exp_opcode op, type *result_type,
type *shift_count_type, const gdb_mpz &shift_count,
- unsigned long &nbits)
+ ULONGEST &nbits)
{
if (!shift_count_type->is_unsigned ())
{
@@ -1112,7 +1112,7 @@ check_valid_shift_count (enum exp_opcode op, type *result_type,
}
}
- nbits = shift_count.as_integer<unsigned long> ();
+ nbits = shift_count.as_integer<ULONGEST> ();
if (nbits >= type_length_bits (result_type))
{
/* In Go, shifting by large amounts is defined. Be silent and
@@ -1291,7 +1291,7 @@ scalar_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
case BINOP_LSH:
{
- unsigned long nbits;
+ ULONGEST nbits;
if (!check_valid_shift_count (op, result_type, type2, v2, nbits))
v = 0;
else
@@ -1301,7 +1301,7 @@ scalar_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
case BINOP_RSH:
{
- unsigned long nbits;
+ ULONGEST nbits;
if (!check_valid_shift_count (op, result_type, type2, v2, nbits))
{
/* Pretend the too-large shift was decomposed in a