public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "bpeeluk at yahoo dot co.uk" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug rust/29859] New: Printing rust expressions with simple arithmetic gets wrong result
Date: Tue, 06 Dec 2022 12:33:36 +0000	[thread overview]
Message-ID: <bug-29859-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=29859

            Bug ID: 29859
           Summary: Printing rust expressions with simple arithmetic gets
                    wrong result
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: rust
          Assignee: unassigned at sourceware dot org
          Reporter: bpeeluk at yahoo dot co.uk
  Target Milestone: ---

The rust parser doesn’t seem to handle expressions with multiple binary
operators but no parentheses correctly:

(gdb) p 3 - 2 - 1
$1 = 2
(gdb) p 5 * 4 / 3
$2 = 5

It seems to be calculating the answer as if the operators were right-to-left:

(gdb) p 3 - (2 - 1)
$3 = 2
(gdb) p 5 * (4 / 3)
$4 = 5

But it should be doing left-to-right:

(gdb) p (3 - 2) - 1
$5 = 0
(gdb) p (5 * 4) / 3
$6 = 6

I tested this with the current git master which is c8ea5e409b02cf7fa8.

Another way to test this could be to add the following lines to the bottom of
gdb/testsuite/gdb.rust/expr.exp:

gdb_test "print 3 - 2 - 1" " = 0"
gdb_test "print 5 * 4 / 3" " = 6"

and then run:

( cd gdb/testsuite && runtest gdb.rust/expr.exp )

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2022-12-06 12:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06 12:33 bpeeluk at yahoo dot co.uk [this message]
2022-12-06 14:14 ` [Bug rust/29859] " tromey at sourceware dot org
2022-12-06 14:43 ` cvs-commit at gcc dot gnu.org
2022-12-06 14:43 ` tromey at sourceware dot org
2022-12-06 15:37 ` bpeeluk at yahoo dot co.uk
2022-12-06 22:14 ` tromey at sourceware dot org
2022-12-12 13:44 ` cvs-commit at gcc dot gnu.org
2022-12-12 13:46 ` tromey at sourceware dot org
2022-12-13 13:01 ` bpeeluk at yahoo dot co.uk

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-29859-4717@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).