public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug c++/31590] (-3) >> 1 should be -2.
Date: Tue, 11 Jun 2024 18:37:18 +0000	[thread overview]
Message-ID: <bug-31590-4717-nkpHqYJYnH@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-31590-4717@http.sourceware.org/bugzilla/>

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.

  parent reply	other threads:[~2024-06-11 18:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02  5:57 [Bug gdb/31590] New: " 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-31590-4717-nkpHqYJYnH@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).