]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Do not crash on empty macros expand. Fixes #1712
authorLyra <teromene@teromene.fr>
Tue, 24 Jan 2023 13:15:42 +0000 (14:15 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 6 Apr 2023 08:47:17 +0000 (10:47 +0200)
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>
gcc/rust/expand/rust-macro-expand.cc
gcc/testsuite/rust/compile/macro45.rs [new file with mode: 0644]

index 9c3523e05151d4ccb0da24755d4ac17a2cae15dc..bf914ee19e366a8bff39a2c87b291c03d01a8d5e 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!();
+}