aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorHannes Domani <ssbssa@yahoo.de>2024-06-11 20:32:27 +0200
committerHannes Domani <ssbssa@yahoo.de>2024-06-11 20:36:34 +0200
commitd17731525424349d7e63b517acf9f45114979fbb (patch)
tree551ab6e2d134944cc2b81fb84fe073ef27b67d91 /gdb/testsuite
parent4bafd5b7f377bac19a6dad748f6a162556696c01 (diff)
downloadbinutils-d17731525424349d7e63b517acf9f45114979fbb.zip
binutils-d17731525424349d7e63b517acf9f45114979fbb.tar.gz
binutils-d17731525424349d7e63b517acf9f45114979fbb.tar.bz2
Fix right shift of negative numbers
PR31590 shows that right shift of negative numbers doesn't work correctly since GDB 14: (gdb) p (-3) >> 1 $1 = -1 GDB 13 and earlier returned the correct value -2. And there actually is one test that shows the failure: print -1 >> 1 $84 = 0 (gdb) FAIL: gdb.base/bitshift.exp: lang=asm: rsh neg lhs: print -1 >> 1 The problem was introduced with the change to gmp functions in commit 303a881f87. It's wrong because gdb_mpz::operator>> uses mpz_tdif_q_2exp, which always rounds toward zero, and the gmp docu says this: For positive n both mpz_fdiv_q_2exp and mpz_tdiv_q_2exp are simple bitwise right shifts. For negative n, mpz_fdiv_q_2exp is effectively an arithmetic right shift treating n as two's complement the same as the bitwise logical functions do, whereas mpz_tdiv_q_2exp effectively treats n as sign and magnitude. So this changes mpz_tdiv_q_2exp to mpz_fdiv_q_2exp, since it does right shifts for both positive and negative numbers. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31590 Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.base/bitshift.exp2
1 files changed, 2 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/bitshift.exp b/gdb/testsuite/gdb.base/bitshift.exp
index 61c7eca..17f6b78 100644
--- a/gdb/testsuite/gdb.base/bitshift.exp
+++ b/gdb/testsuite/gdb.base/bitshift.exp
@@ -344,6 +344,8 @@ proc test_shifts {} {
with_test_prefix "rsh neg lhs" {
test_shift $lang "print -1 >> 0" " = -1"
test_shift $lang "print -1 >> 1" " = -1"
+ test_shift $lang "print -2 >> 1" " = -1"
+ test_shift $lang "print -3 >> 1" " = -2"
test_shift $lang "print -8 >> 1" " = -4"
test_shift $lang "print [make_int64 $lang -8] >> 1" " = -4"
}