]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Do not crash on empty macros expand. Fixes #1712
authorLyra <teromene@teromene.fr>
Tue, 24 Jan 2023 13:15:42 +0000 (14:15 +0100)
committerLyra <teromene@teromene.fr>
Tue, 24 Jan 2023 14:05:09 +0000 (15:05 +0100)
This commit fixes a compiler crash when expanding an empty macro into an existing AST.

Signed-off-by: Lyra Karenai <teromene@teromene.fr>
gcc/rust/expand/rust-macro-expand.cc
gcc/testsuite/rust/compile/macro45.rs [new file with mode: 0644]

index 589443453d6aef3962dbf9559a0a563cc458224b..36b3195f912bda8d35d4cb0b49987666cae356b9 100644 (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)});
 }
diff --git a/gcc/testsuite/rust/compile/macro45.rs b/gcc/testsuite/rust/compile/macro45.rs
new file mode 100644 (file)
index 0000000..52dbcbb
--- /dev/null
@@ -0,0 +1,7 @@
+macro_rules! empty {
+    () => {}; // { dg-error "found unexpected token '\}' in null denotation" }
+}
+
+fn main() {
+    let a = empty!();
+}