public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug rust/29859] New: Printing rust expressions with simple arithmetic gets wrong result
@ 2022-12-06 12:33 bpeeluk at yahoo dot co.uk
  2022-12-06 14:14 ` [Bug rust/29859] " tromey at sourceware dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: bpeeluk at yahoo dot co.uk @ 2022-12-06 12:33 UTC (permalink / raw)
  To: gdb-prs

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-12-13 13:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 12:33 [Bug rust/29859] New: Printing rust expressions with simple arithmetic gets wrong result bpeeluk at yahoo dot co.uk
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

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).