aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-01-24 16:39:54 +0000
committerGitHub <noreply@github.com>2023-01-24 16:39:54 +0000
commit6a320bca7be0535b1e402ee48741df15c8e0aa8d (patch)
treedeb71fc1199717cd2e74adea098fd0d8c40b37ba /gcc
parent7558c183a11db3f53275c2f4691e3575a6b014e4 (diff)
parentfc0c03dcf756c89694845484abd7d74ed080fdb6 (diff)
downloadgcc-6a320bca7be0535b1e402ee48741df15c8e0aa8d.zip
gcc-6a320bca7be0535b1e402ee48741df15c8e0aa8d.tar.gz
gcc-6a320bca7be0535b1e402ee48741df15c8e0aa8d.tar.bz2
Merge #1763
1763: Do not crash on empty macros expand. Fixes #1712 r=philberty a=teromene This PR fixes a compiler crash when expanding an empty macro into an existing AST. (I ran clang-format but it marked a few other files as dirty, and I therefore did not touch them) Signed-off-by: Lyra Karenai <teromene@teromene.fr> Co-authored-by: Lyra <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 5894434..36b3195 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!();
+}