[gcc r16-5593] gccrs: fix segfault in clone_pattern w macro
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Nov 25 21:58:31 GMT 2025
https://gcc.gnu.org/g:5be67e843c577e322d23885776d0de3ee6d66bd1
commit r16-5593-g5be67e843c577e322d23885776d0de3ee6d66bd1
Author: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
Date: Wed Oct 15 15:07:05 2025 +0000
gccrs: fix segfault in clone_pattern w macro
Check if parser throw an error to avoid cloning nullptr
Fixes Rust-GCC#4140
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (transcribe_expression): Check if
parser didn't fail.
(transcribe_type): Likewise.
(transcribe_pattern): Likewise.
Signed-off-by: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
Diff:
---
gcc/rust/expand/rust-macro-expand.cc | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index 52f8e2b10e33..b47e43afd764 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -962,12 +962,10 @@ transcribe_expression (Parser<MacroInvocLexer> &parser)
auto attrs = parser.parse_outer_attributes ();
auto expr = parser.parse_expr (std::move (attrs));
- if (expr == nullptr)
- {
- for (auto error : parser.get_errors ())
- error.emit ();
- return AST::Fragment::create_error ();
- }
+ for (auto error : parser.get_errors ())
+ error.emit ();
+ if (!expr)
+ return AST::Fragment::create_error ();
// FIXME: make this an error for some edititons
if (parser.peek_current_token ()->get_id () == SEMICOLON)
@@ -997,6 +995,8 @@ transcribe_type (Parser<MacroInvocLexer> &parser)
auto type = parser.parse_type (true);
for (auto err : parser.get_errors ())
err.emit ();
+ if (!type)
+ return AST::Fragment::create_error ();
auto end = lexer.get_offs ();
@@ -1018,6 +1018,9 @@ transcribe_pattern (Parser<MacroInvocLexer> &parser)
for (auto err : parser.get_errors ())
err.emit ();
+ if (!pattern)
+ return AST::Fragment::create_error ();
+
auto end = lexer.get_offs ();
return AST::Fragment ({std::move (pattern)},
More information about the Gcc-cvs
mailing list