gccrs: Do not crash on empty macros expand. Fixes #1712

This commit fixes a compiler crash when expanding an empty macro into an existing AST.

gcc/rust/ChangeLog:

	* expand/rust-macro-expand.cc (transcribe_expression): Fix ICE when expanding
	empty macros.

gcc/testsuite/ChangeLog:

	* rust/compile/macro45.rs: New test.

Signed-off-by: Lyra Karenai <teromene@teromene.fr>
This commit is contained in:
Lyra
2023-01-24 14:15:42 +01:00
committed by Arthur Cohen
parent 910e7e0a95
commit cb42610bfb
2 changed files with 9 additions and 0 deletions

View File

@@ -839,6 +839,8 @@ static AST::Fragment
transcribe_expression (Parser<MacroInvocLexer> &parser)
{
auto expr = parser.parse_expr ();
if (expr == nullptr)
return AST::Fragment::create_error ();
return AST::Fragment::complete ({std::move (expr)});
}

View File

@@ -0,0 +1,7 @@
macro_rules! empty {
() => {}; // { dg-error "found unexpected token '\}' in null denotation" }
}
fn main() {
let a = empty!();
}