aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-03-24 13:50:03 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2022-03-24 13:56:23 +0100
commit912b04216d71a2cd95001cfb0570095db1824207 (patch)
tree71c5fcd9398ab535680db27cd48d8155fa0e874d
parent8283724bc24efc0c11960947f2d4e99bc20b3765 (diff)
downloadgcc-912b04216d71a2cd95001cfb0570095db1824207.zip
gcc-912b04216d71a2cd95001cfb0570095db1824207.tar.gz
gcc-912b04216d71a2cd95001cfb0570095db1824207.tar.bz2
macros: Check follow-set restrictions on matcher's first delimiter
-rw-r--r--gcc/rust/parse/rust-parse.cc22
-rw-r--r--gcc/testsuite/rust/compile/macro39.rs5
2 files changed, 24 insertions, 3 deletions
diff --git a/gcc/rust/parse/rust-parse.cc b/gcc/rust/parse/rust-parse.cc
index 0153b37..900964e 100644
--- a/gcc/rust/parse/rust-parse.cc
+++ b/gcc/rust/parse/rust-parse.cc
@@ -202,9 +202,25 @@ peculiar_fragment_match_compatible (AST::MacroMatchFragment &last_match,
}
case AST::MacroMatch::Matcher: {
auto matcher = static_cast<AST::MacroMatcher *> (&match);
- auto &matches = matcher->get_matches ();
- if (!matches.empty ())
- error_locus = matches.front ()->get_match_locus ();
+ auto first_token = matcher->get_delim_type ();
+ TokenId delim_id;
+ switch (first_token)
+ {
+ case AST::PARENS:
+ delim_id = LEFT_PAREN;
+ break;
+ case AST::SQUARE:
+ delim_id = LEFT_SQUARE;
+ break;
+ case AST::CURLY:
+ delim_id = LEFT_CURLY;
+ break;
+ }
+ if (contains (allowed_toks, delim_id))
+ return true;
+ kind_str = "token `" + std::string (get_token_description (delim_id))
+ + "` at start of matcher";
+ error_locus = matcher->get_match_locus ();
break;
}
case AST::MacroMatch::Fragment: {
diff --git a/gcc/testsuite/rust/compile/macro39.rs b/gcc/testsuite/rust/compile/macro39.rs
new file mode 100644
index 0000000..f5c498c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macro39.rs
@@ -0,0 +1,5 @@
+macro_rules! m {
+ ($e:expr (, parenthesis_forbidden)) => {{}}; // { dg-error "token .\\(. at start of matcher is not allowed after .expr. fragment" }
+ // { dg-error "required first macro rule" "" { target *-*-* } .-1 }
+ // { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 }
+}