From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 326773888833; Fri, 5 Jul 2024 19:45:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 326773888833 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1720208723; bh=8sLcrUOwZnqurGyqydsJ8nctH4HCNqSlSepY7KbhGvQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YGLMq7moi/umwKYvm4oLmIpJcZjXnuhFseG6Cb6alnzv5O9wPh0TioGOClA5E03tC JOrep3q5PJjQwC1Z/CyIuX7z0gt08LecRJ5AjEaTMtZarvKxM/8IXbFwCT/tYctwtt vLB3qSMYaXOfwu15wJUqJTEYphccp7tk2NF8nIn8= From: "cvs-commit at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug c++/31590] (-3) >> 1 should be -2. Date: Fri, 05 Jul 2024 19:45:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: c++ X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: 16.1 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31590 --- Comment #4 from Sourceware Commits --- The gdb-15-branch branch has been updated by Hannes Domani : https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dedd3f7be255e= 2e51ff7928cabb744af5d3d20018 commit edd3f7be255e2e51ff7928cabb744af5d3d20018 Author: Hannes Domani 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 =3D -1 GDB 13 and earlier returned the correct value -2. And there actually is one test that shows the failure: print -1 >> 1 $84 =3D 0 (gdb) FAIL: gdb.base/bitshift.exp: lang=3Dasm: 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=3D31590 Approved-By: Tom Tromey --=20 You are receiving this mail because: You are on the CC list for the bug.=