public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed] Fix operator precedence bug in Rust parser
@ 2022-12-06 14:42 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-12-06 14:42 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

PR rust/29859 points out an operator precedence bug in the Rust
parser.  This patch fixes it and adds a regression test.
---
 gdb/rust-parse.c                  | 2 +-
 gdb/testsuite/gdb.rust/simple.exp | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index f5eb63ec1e3..337927219d5 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -1398,7 +1398,7 @@ rust_parser::parse_binop (bool required)
 	  break;
         }
 
-      while (precedence < operator_stack.back ().precedence
+      while (precedence <= operator_stack.back ().precedence
 	     && operator_stack.size () > 1)
 	{
 	  rustop_item rhs = std::move (operator_stack.back ());
diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp
index 252c47baac5..3a010f30ea6 100644
--- a/gdb/testsuite/gdb.rust/simple.exp
+++ b/gdb/testsuite/gdb.rust/simple.exp
@@ -412,3 +412,7 @@ if {[lindex $v 0] >= 8} {
     gdb_test "python print(gdb.lookup_type('simple::MoreComplicated').dynamic)" \
 	"True"
 }
+
+# The new parser introduced an operator precedence bug.
+gdb_test "print 5 * 7 / 5" " = 7"
+gdb_test "print 4 - 3 - 1" " = 0"
-- 
2.34.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-06 14:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 14:42 [pushed] Fix operator precedence bug in Rust parser Tom Tromey

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