* [Bug c++/31590] (-3) >> 1 should be -2.
2024-04-02 5:57 [Bug gdb/31590] New: (-3) >> 1 should be -2 tsqurt at outlook dot com
@ 2024-04-02 12:38 ` tromey at sourceware dot org
2024-05-31 11:03 ` ssbssa at sourceware dot org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: tromey at sourceware dot org @ 2024-04-02 12:38 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31590
Tom Tromey <tromey at sourceware dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|gdb |c++
CC| |tromey at sourceware dot org
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/31590] (-3) >> 1 should be -2.
2024-04-02 5:57 [Bug gdb/31590] New: (-3) >> 1 should be -2 tsqurt at outlook dot com
2024-04-02 12:38 ` [Bug c++/31590] " tromey at sourceware dot org
@ 2024-05-31 11:03 ` ssbssa at sourceware dot org
2024-05-31 11:51 ` ssbssa at sourceware dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ssbssa at sourceware dot org @ 2024-05-31 11:03 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31590
Hannes Domani <ssbssa at sourceware dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
CC| |ssbssa at sourceware dot org
Last reconfirmed| |2024-05-31
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/31590] (-3) >> 1 should be -2.
2024-04-02 5:57 [Bug gdb/31590] New: (-3) >> 1 should be -2 tsqurt at outlook dot com
2024-04-02 12:38 ` [Bug c++/31590] " tromey at sourceware dot org
2024-05-31 11:03 ` ssbssa at sourceware dot org
@ 2024-05-31 11:51 ` ssbssa at sourceware dot org
2024-06-11 18:37 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ssbssa at sourceware dot org @ 2024-05-31 11:51 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31590
--- Comment #1 from Hannes Domani <ssbssa at sourceware dot org> ---
https://sourceware.org/pipermail/gdb-patches/2024-May/209509.html
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/31590] (-3) >> 1 should be -2.
2024-04-02 5:57 [Bug gdb/31590] New: (-3) >> 1 should be -2 tsqurt at outlook dot com
` (2 preceding siblings ...)
2024-05-31 11:51 ` ssbssa at sourceware dot org
@ 2024-06-11 18:37 ` cvs-commit at gcc dot gnu.org
2024-06-12 14:42 ` ssbssa at sourceware dot org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-11 18:37 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31590
--- Comment #2 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d17731525424349d7e63b517acf9f45114979fbb
commit d17731525424349d7e63b517acf9f45114979fbb
Author: Hannes Domani <ssbssa@yahoo.de>
Date: Tue Jun 11 20:32:27 2024 +0200
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>
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/31590] (-3) >> 1 should be -2.
2024-04-02 5:57 [Bug gdb/31590] New: (-3) >> 1 should be -2 tsqurt at outlook dot com
` (3 preceding siblings ...)
2024-06-11 18:37 ` cvs-commit at gcc dot gnu.org
@ 2024-06-12 14:42 ` ssbssa at sourceware dot org
2024-07-05 19:45 ` cvs-commit at gcc dot gnu.org
2024-07-05 19:47 ` ssbssa at sourceware dot org
6 siblings, 0 replies; 8+ messages in thread
From: ssbssa at sourceware dot org @ 2024-06-12 14:42 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31590
Hannes Domani <ssbssa at sourceware dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |16.1
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #3 from Hannes Domani <ssbssa at sourceware dot org> ---
Fixed.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/31590] (-3) >> 1 should be -2.
2024-04-02 5:57 [Bug gdb/31590] New: (-3) >> 1 should be -2 tsqurt at outlook dot com
` (4 preceding siblings ...)
2024-06-12 14:42 ` ssbssa at sourceware dot org
@ 2024-07-05 19:45 ` cvs-commit at gcc dot gnu.org
2024-07-05 19:47 ` ssbssa at sourceware dot org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-05 19:45 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31590
--- Comment #4 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The gdb-15-branch branch has been updated by Hannes Domani
<ssbssa@sourceware.org>:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=edd3f7be255e2e51ff7928cabb744af5d3d20018
commit edd3f7be255e2e51ff7928cabb744af5d3d20018
Author: Hannes Domani <ssbssa@yahoo.de>
Date: Tue Jun 11 20:32:27 2024 +0200
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>
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/31590] (-3) >> 1 should be -2.
2024-04-02 5:57 [Bug gdb/31590] New: (-3) >> 1 should be -2 tsqurt at outlook dot com
` (5 preceding siblings ...)
2024-07-05 19:45 ` cvs-commit at gcc dot gnu.org
@ 2024-07-05 19:47 ` ssbssa at sourceware dot org
6 siblings, 0 replies; 8+ messages in thread
From: ssbssa at sourceware dot org @ 2024-07-05 19:47 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=31590
Hannes Domani <ssbssa at sourceware dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|16.1 |15.1
--- Comment #5 from Hannes Domani <ssbssa at sourceware dot org> ---
Now fixed for the upcoming 15.1 release as well.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread