From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gproxy2-pub.mail.unifiedlayer.com (gproxy2-pub.mail.unifiedlayer.com [69.89.18.3]) by sourceware.org (Postfix) with ESMTPS id C322C385456A for ; Mon, 12 Dec 2022 13:42:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C322C385456A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw13.mail.unifiedlayer.com (unknown [10.0.90.128]) by progateway4.mail.pro1.eigbox.com (Postfix) with ESMTP id 106A210047113 for ; Mon, 12 Dec 2022 13:41:57 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id 4j48pgon43A764j49pYHeF; Mon, 12 Dec 2022 13:41:57 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=X/uXlEfe c=1 sm=1 tr=0 ts=63972fa5 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=sHyYjHe8cH0A:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=KqVZJS9xW1PMY5W76EsA:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=l35vOmFTAn5ALYNUHdD+1vQng9zS3u2P2ZRbMNAPprA=; b=eaUJRR0nV8pPIbD/FSqqxwJof1 B13FmRloYLVcPntdKq/J5F+YoH4DeeVOo8jCssNfNO8tGD1fN2YithbfYCelk6SmcBuOpg7bsrSkJ 56ebwnp0VBMjPaFj6Y7480w6m; Received: from [161.98.8.3] (port=33844 helo=prentzel.ci.boulder.co.us) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1p4j47-0005WH-WE; Mon, 12 Dec 2022 06:41:56 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [pushed] Another Rust operator precedence bug Date: Mon, 12 Dec 2022 06:41:50 -0700 Message-Id: <20221212134150.375769-1-tom@tromey.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 161.98.8.3 X-Source-L: No X-Exim-ID: 1p4j47-0005WH-WE X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (prentzel.ci.boulder.co.us) [161.98.8.3]:33844 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3028.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 --- gdb/rust-parse.c | 10 ++++++++-- gdb/testsuite/gdb.rust/simple.exp | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index 337927219d5..f28514ab2da 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -1344,6 +1344,8 @@ rust_parser::parse_binop (bool required) OPERATION (ANDAND, 2, logical_and_operation) \ OPERATION (OROR, 1, logical_or_operation) +#define ASSIGN_PREC 0 + operation_up start = parse_atom (required); if (start == nullptr) { @@ -1376,7 +1378,7 @@ rust_parser::parse_binop (bool required) compound_assign_op = current_opcode; /* FALLTHROUGH */ case '=': - precedence = 0; + precedence = ASSIGN_PREC; lex (); break; @@ -1398,7 +1400,11 @@ rust_parser::parse_binop (bool required) break; } - while (precedence <= operator_stack.back ().precedence + /* Make sure that assignments are right-associative while other + operations are left-associative. */ + while ((precedence == ASSIGN_PREC + ? precedence < operator_stack.back ().precedence + : 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 3a010f30ea6..0fb06af9380 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -416,3 +416,6 @@ if {[lindex $v 0] >= 8} { # The new parser introduced an operator precedence bug. gdb_test "print 5 * 7 / 5" " = 7" gdb_test "print 4 - 3 - 1" " = 0" + +# Another operator precedence bug. +gdb_test "print \$one = \$two = 75" " = \\\(\\\)" -- 2.38.1