public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix inner attribute parsing
@ 2021-06-27 15:12 Mark Wielaard
  2021-06-27 19:17 ` Marc
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2021-06-27 15:12 UTC (permalink / raw)
  To: gcc-rust; +Cc: tom, Mark Wielaard

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<ManagedTokenSource>::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<ManagedTokenSource>::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<AST::AttrInput> 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix inner attribute parsing
  2021-06-27 15:12 [PATCH] Fix inner attribute parsing Mark Wielaard
@ 2021-06-27 19:17 ` Marc
  0 siblings, 0 replies; 2+ messages in thread
From: Marc @ 2021-06-27 19:17 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: gcc-rust, tom

Mark Wielaard <mark@klomp.org> writes:

> 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

Hi Mark,

Sent to GH: https://github.com/Rust-GCC/gccrs/pull/530

Thanks :)
Marc

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-27 19:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 15:12 [PATCH] Fix inner attribute parsing Mark Wielaard
2021-06-27 19:17 ` Marc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).