aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorLyra <teromene@teromene.fr>2023-01-24 14:15:42 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2023-04-06 10:47:17 +0200
commitcb42610bfbabdbd78a1a92eff4905551ecca8932 (patch)
treefa752a2694a2ae40b435371640ccb42f729f77e9 /gcc
parent910e7e0a9586add4b6e1229e576e4f870c2ae030 (diff)
downloadgcc-cb42610bfbabdbd78a1a92eff4905551ecca8932.zip
gcc-cb42610bfbabdbd78a1a92eff4905551ecca8932.tar.gz
gcc-cb42610bfbabdbd78a1a92eff4905551ecca8932.tar.bz2
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/expand/rust-macro-expand.cc2
-rw-r--r--gcc/testsuite/rust/compile/macro45.rs7
2 files changed, 9 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index 9c3523e..bf914ee 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<MacroInvocLexer> &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 0000000..52dbcbb
--- /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!();
+}