Skip to content

Commit 72967d7

Browse files
committed
Prevent segfault on builtin metavars
Builtin metavars are not in the fragment, the compiler should not emit an error message. gcc/rust/ChangeLog: * expand/rust-macro-substitute-ctx.cc (is_builtin_metavariable): Add function to check builtin metavars knowledge. (SubstituteCtx::check_repetition_amount): Do not process missing fragment. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
1 parent 73060d4 commit 72967d7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

gcc/rust/expand/rust-macro-substitute-ctx.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ SubstituteCtx::substitute_metavar (
108108
return true;
109109
}
110110

111+
static bool
112+
is_builtin_metavariable (AST::Token &token)
113+
{
114+
return token.get_id () == CRATE;
115+
}
116+
111117
bool
112118
SubstituteCtx::check_repetition_amount (size_t pattern_start,
113119
size_t pattern_end,
@@ -125,6 +131,10 @@ SubstituteCtx::check_repetition_amount (size_t pattern_start,
125131
|| frag_token->get_id () == IDENTIFIER)
126132
{
127133
auto it = fragments.find (frag_token->get_str ());
134+
135+
if (is_builtin_metavariable (*frag_token))
136+
continue;
137+
128138
if (it == fragments.end ())
129139
{
130140
// If the repetition is not anything we know (ie no declared
@@ -136,6 +146,7 @@ SubstituteCtx::check_repetition_amount (size_t pattern_start,
136146
frag_token->get_str ().c_str ());
137147

138148
is_valid = false;
149+
continue;
139150
}
140151

141152
auto &fragment = *it->second;

0 commit comments

Comments
 (0)