From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 02C083846999; Tue, 6 Dec 2022 14:43:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02C083846999 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670337782; bh=MyyChfIaDhb8U5Rw6/KCVVIZ8XevJ/hbQWpjhx7ydOE=; h=From:To:Subject:Date:From; b=PukK0jeI/cyMTd/b+g89JuolSJtJ+H5BI0mVWVAJdfpxB0R578Qw3QHWSqeAD9Iud itoZritVDsNAUYk13vNooaYzR/wDRRyUDuLMuO8u5jWrGfqLVu4ZBdGLuAxwy2LwnV kAzDIqcy9C9bcJH8defm/2C6nBYcWKIcbu7Mdjag= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix operator precedence bug in Rust parser X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 83f18e5ebe627163f744215d3760a8eaacee6ec1 X-Git-Newrev: e03698c1227bc18835cc2e4a9146a8369635e119 Message-Id: <20221206144302.02C083846999@sourceware.org> Date: Tue, 6 Dec 2022 14:43:02 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De03698c1227b= c18835cc2e4a9146a8369635e119 commit e03698c1227bc18835cc2e4a9146a8369635e119 Author: Tom Tromey Date: Tue Dec 6 07:41:52 2022 -0700 Fix operator precedence bug in Rust parser =20 PR rust/29859 points out an operator precedence bug in the Rust parser. This patch fixes it and adds a regression test. Diff: --- 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; } =20 - while (precedence < operator_stack.back ().precedence + while (precedence <=3D operator_stack.back ().precedence && operator_stack.size () > 1) { rustop_item rhs =3D std::move (operator_stack.back ()); diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/sim= ple.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] >=3D 8} { gdb_test "python print(gdb.lookup_type('simple::MoreComplicated').dyna= mic)" \ "True" } + +# The new parser introduced an operator precedence bug. +gdb_test "print 5 * 7 / 5" " =3D 7" +gdb_test "print 4 - 3 - 1" " =3D 0"