From patchwork Tue Dec 6 14:42:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 61572 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2F39D38469B2 for ; Tue, 6 Dec 2022 14:43:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F39D38469B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670337799; bh=biMGaOig8/d50FOGD3azWjyuIPhzW4GQgfevK/e+28c=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=AfvM4O23WflSoFIkxZkkI4NfR3bcNjk6A5D82Y1jbkEQYA89UPiVDynbYdLXv6Pdk J+VPzfGUVG5Q/4tq0BsEqYtUkFNZYf4P6N3qGy5mhCzdUmEH32l/unR0nCB537ZWzT 7lGf/l02YABPTvf79KM4H4oz2nuABABvP2XROEMQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id 029693846982 for ; Tue, 6 Dec 2022 14:42:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 029693846982 Received: by mail-io1-xd35.google.com with SMTP id n188so9810159iof.8 for ; Tue, 06 Dec 2022 06:42:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=biMGaOig8/d50FOGD3azWjyuIPhzW4GQgfevK/e+28c=; b=oyZXSPQMB1v+opFDoy8oYCPok5TBtZx/NiV+TCiF5mXFE6NtXRM3Dvy099MqStXSm2 GlciNGXwx/hCWlTjmqiZqk4t4pQW91k7a1LFI6nVWGjzDSyY/nFUAFVro6jcGOcq1WjV BD5TtNiq/ADYf3rGnx3jbuFhvdzAF2Cc6AzAxMK42vovWlEGclrL7mG2vmmRBp6eYEoH Bw5SWNMg6DSlE3E5ZS2r9tn+th9jfQyCxha0WOPW2dascoBui1nWtQBza/EL6tPsV4H/ IRFvtL5o5sBfmkw35YkO2IWBsAMKEH9zbActadPh3g3ZVEY8uy5KixShYsZZK6UjwHwu KlaA== X-Gm-Message-State: ANoB5pmw0i0wzfgOfX7LcGZzyqBuGp31n9SiY7gEedubbYSLqUc8P0tv ki8LDRl+1/0q7dx6CdIP8eTpMjeLzxTXvr3X X-Google-Smtp-Source: AA0mqf6JLDBpFRh+DuXuH5xoMVjCa+p2wFyScPidMcWSnQxoWulfxq1zo6mWzUyO19p/1X7nZw2N0w== X-Received: by 2002:a5d:88c3:0:b0:6d6:5fe4:8212 with SMTP id i3-20020a5d88c3000000b006d65fe48212mr40546280iol.180.1670337774215; Tue, 06 Dec 2022 06:42:54 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id h37-20020a022b25000000b00374cd28d842sm6926272jaa.104.2022.12.06.06.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 06:42:53 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [pushed] Fix operator precedence bug in Rust parser Date: Tue, 6 Dec 2022 07:42:47 -0700 Message-Id: <20221206144247.2733712-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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"