From cb42610bfbabdbd78a1a92eff4905551ecca8932 Mon Sep 17 00:00:00 2001 From: Lyra Date: Tue, 24 Jan 2023 14:15:42 +0100 Subject: [PATCH] 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 --- gcc/rust/expand/rust-macro-expand.cc | 2 ++ gcc/testsuite/rust/compile/macro45.rs | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 gcc/testsuite/rust/compile/macro45.rs diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 9c3523e05151..bf914ee19e36 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -839,6 +839,8 @@ static AST::Fragment transcribe_expression (Parser &parser) { auto expr = parser.parse_expr (); + if (expr == nullptr) + return AST::Fragment::create_error (); return AST::Fragment::complete ({std::move (expr)}); } diff --git a/gcc/testsuite/rust/compile/macro45.rs b/gcc/testsuite/rust/compile/macro45.rs new file mode 100644 index 000000000000..52dbcbb00169 --- /dev/null +++ b/gcc/testsuite/rust/compile/macro45.rs @@ -0,0 +1,7 @@ +macro_rules! empty { + () => {}; // { dg-error "found unexpected token '\}' in null denotation" } +} + +fn main() { + let a = empty!(); +} -- 2.47.2