From: Tom Tromey Date: Tue, 6 Dec 2022 14:41:52 +0000 (-0700) Subject: Fix operator precedence bug in Rust parser X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e03698c1227bc18835cc2e4a9146a8369635e119;p=binutils-gdb.git 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. --- 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"