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

* [Bug rust/29859] Printing rust expressions with simple arithmetic gets wrong result
  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 ` tromey at sourceware dot org
  2022-12-06 14:43 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2022-12-06 14:14 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-12-06
     Ever confirmed|0                           |1
           Assignee|unassigned at sourceware dot org   |tromey at sourceware dot org
                 CC|                            |tromey at sourceware dot org
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
Ugh.  Looks like an operator precedence error in the parser rewrite :(

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

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

* [Bug rust/29859] Printing rust expressions with simple arithmetic gets wrong result
  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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-06 14:43 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e03698c1227bc18835cc2e4a9146a8369635e119

commit e03698c1227bc18835cc2e4a9146a8369635e119
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Dec 6 07:41:52 2022 -0700

    Fix operator precedence bug in Rust parser

    PR rust/29859 points out an operator precedence bug in the Rust
    parser.  This patch fixes it and adds a regression test.

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

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

* [Bug rust/29859] Printing rust expressions with simple arithmetic gets wrong result
  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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2022-12-06 14:43 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |13.1

--- Comment #3 from Tom Tromey <tromey at sourceware dot org> ---
Fixed.  Sorry about that.

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

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

* [Bug rust/29859] Printing rust expressions with simple arithmetic gets wrong result
  2022-12-06 12:33 [Bug rust/29859] New: Printing rust expressions with simple arithmetic gets wrong result bpeeluk at yahoo dot co.uk
                   ` (2 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bpeeluk at yahoo dot co.uk @ 2022-12-06 15:37 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #4 from Neil Roberts <bpeeluk at yahoo dot co.uk> ---
Thanks for the very quick response.

This is just nitpicking and I guess it doesn’t really matter, but I’d like to
point out that this commit has effectively changed all operators to be
left-to-right associative whereas previously they were all right-to-left
associative. This is clearly an improvement because almost all of the operators
are supposed to be left-to-right. However, the assignment operators really are
supposed to be right-to-left as you can see in the Rust docs:
https://doc.rust-lang.org/reference/expressions.html#expression-precedence

So now we have a regression where previously we had this correct behaviour:

(gdb) p $a = $b = 3
$1 = ()

This was being interpreted as $a = ($b = 3). The value of an assignment
expression is () (unlike in C), so $a becomes ().

After the patch it gives an error:

(gdb) p $a = $b = 3
Left operand of assignment is not an lvalue.

That’s presumably because it’s being interpreted as “($a = $b) = 3” and “$a =
$b” isn’t an lvalue.

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

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

* [Bug rust/29859] Printing rust expressions with simple arithmetic gets wrong result
  2022-12-06 12:33 [Bug rust/29859] New: Printing rust expressions with simple arithmetic gets wrong result bpeeluk at yahoo dot co.uk
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2022-12-06 22:14 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #5 from Tom Tromey <tromey at sourceware dot org> ---
I'll fix that too, sorry.

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

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

* [Bug rust/29859] Printing rust expressions with simple arithmetic gets wrong result
  2022-12-06 12:33 [Bug rust/29859] New: Printing rust expressions with simple arithmetic gets wrong result bpeeluk at yahoo dot co.uk
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-12 13:44 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #6 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=67a8c89601f6e1947484d5de23411634fef92e68

commit 67a8c89601f6e1947484d5de23411634fef92e68
Author: Tom Tromey <tom@tromey.com>
Date:   Mon Dec 12 06:36:55 2022 -0700

    Another Rust operator precedence bug

    My earlier patch to fix PR rust/29859 introduced a new operator
    precedence bug in the Rust parser.  Assignment operators are
    right-associative in Rust.  And, while this doesn't often matter, as
    Rust assignments always have the value (), still as a matter of
    principle we should get this correct.

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

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

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

* [Bug rust/29859] Printing rust expressions with simple arithmetic gets wrong result
  2022-12-06 12:33 [Bug rust/29859] New: Printing rust expressions with simple arithmetic gets wrong result bpeeluk at yahoo dot co.uk
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2022-12-12 13:46 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|REOPENED                    |RESOLVED

--- Comment #7 from Tom Tromey <tromey at sourceware dot org> ---
Ok, should be fixed again.

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

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

* [Bug rust/29859] Printing rust expressions with simple arithmetic gets wrong result
  2022-12-06 12:33 [Bug rust/29859] New: Printing rust expressions with simple arithmetic gets wrong result bpeeluk at yahoo dot co.uk
                   ` (6 preceding siblings ...)
  2022-12-12 13:46 ` tromey at sourceware dot org
@ 2022-12-13 13:01 ` bpeeluk at yahoo dot co.uk
  7 siblings, 0 replies; 9+ messages in thread
From: bpeeluk at yahoo dot co.uk @ 2022-12-13 13:01 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #8 from Neil Roberts <bpeeluk at yahoo dot co.uk> ---
Brilliant, thank you!

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