aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-parse.c
diff options
context:
space:
mode:
authorHannes Domani <ssbssa@yahoo.de>2024-06-11 20:32:27 +0200
committerHannes Domani <ssbssa@yahoo.de>2024-07-05 21:42:53 +0200
commitedd3f7be255e2e51ff7928cabb744af5d3d20018 (patch)
tree9479b48a3fa522de5c632d675e37e8efb37b43d3 /gdb/rust-parse.c
parent041fb9da7dc674bb335a0a26443a4b4339e995f9 (diff)
downloadgdb-edd3f7be255e2e51ff7928cabb744af5d3d20018.zip
gdb-edd3f7be255e2e51ff7928cabb744af5d3d20018.tar.gz
gdb-edd3f7be255e2e51ff7928cabb744af5d3d20018.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/rust-parse.c')
0 files changed, 0 insertions, 0 deletions