From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id D33973857808 for ; Sun, 27 Jun 2021 15:12:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D33973857808 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x0b.wildebeest.org [172.31.17.141]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id CF07F30012DF; Sun, 27 Jun 2021 17:12:14 +0200 (CEST) Received: by reform (Postfix, from userid 1000) id 615312E80D21; Sun, 27 Jun 2021 17:12:14 +0200 (CEST) From: Mark Wielaard To: gcc-rust@gcc.gnu.org Cc: tom@tromey.com, Mark Wielaard Subject: [PATCH] Fix inner attribute parsing Date: Sun, 27 Jun 2021 17:12:02 +0200 Message-Id: <20210627151202.238046-1-mark@klomp.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Jun 2021 15:12:19 -0000 parse_inner_attribute tried to skip the right square token twice. This caused odd error messages in case there were multiple inner attributes. This bug masked another bug in parse_attr_input where when the (optional) attr input was an assignment to a literal the parser failed to skip the literal. The existing top_attr.rs testcase relied on the two bugs cancelling each other out. Add a new testcase inner_attributes.rs for the first bug. Resolves: https://github.com/Rust-GCC/gccrs/issues/510 --- gcc/rust/parse/rust-parse-impl.h | 2 +- gcc/testsuite/rust/compile/torture/inner_attributes.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/torture/inner_attributes.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 014beaf9e9c..23e62349e40 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -495,7 +495,6 @@ Parser::parse_inner_attribute () return AST::Attribute::create_empty (); AST::Attribute actual_attribute = parse_attribute_body (); - lexer.skip_token (); if (!skip_token (RIGHT_SQUARE)) return AST::Attribute::create_empty (); @@ -785,6 +784,7 @@ Parser::parse_attr_input () // create actual LiteralExpr AST::LiteralExpr lit_expr (t->get_str (), lit_type, t->get_type_hint (), {}, t->get_locus ()); + lexer.skip_token (); std::unique_ptr attr_input_lit ( new AST::AttrInputLiteral (std::move (lit_expr))); diff --git a/gcc/testsuite/rust/compile/torture/inner_attributes.rs b/gcc/testsuite/rust/compile/torture/inner_attributes.rs new file mode 100644 index 00000000000..3410dd6ec87 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/inner_attributes.rs @@ -0,0 +1,3 @@ +#![allow(dead_code)] +#![allow(unused_variables)] +pub fn main () { } -- 2.32.0