aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorMarc Poulhiès <dkm@kataplop.net>2022-10-07 18:48:36 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2023-02-21 12:36:33 +0100
commit570415e75c42a6346724859d12f38ec3faa9edd8 (patch)
tree2a2df3e65113beae096b31436202d4f9fb8d6257 /gcc/rust
parentab6d8ad3f5957c88208cac2b397ac070d341db1a (diff)
downloadgcc-570415e75c42a6346724859d12f38ec3faa9edd8.zip
gcc-570415e75c42a6346724859d12f38ec3faa9edd8.tar.gz
gcc-570415e75c42a6346724859d12f38ec3faa9edd8.tar.bz2
gccrs: fix ICE on missing closing paren
Fix crash (segfault) on a missing closing parenthesis when parsing the expressions in a block. The returned `expr` was missing a check before being used. Add corresponding test. Signed-off-by: Marc Poulhiès <dkm@kataplop.net> gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_stmt_or_expr_without_block): Check if `expr` is valid after parsing it. gcc/testsuite/ChangeLog: * rust/compile/missing_closing_paren.rs: New test.
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 72207a1..a4a912f 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -11738,10 +11738,17 @@ Parser<ManagedTokenSource>::parse_stmt_or_expr_without_block ()
// must be expression statement
lexer.skip_token ();
- std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
- new AST::ExprStmtWithoutBlock (std::move (expr),
- t->get_locus ()));
- return ExprOrStmt (std::move (stmt));
+ if (expr)
+ {
+ std::unique_ptr<AST::ExprStmtWithoutBlock> stmt (
+ new AST::ExprStmtWithoutBlock (std::move (expr),
+ t->get_locus ()));
+ return ExprOrStmt (std::move (stmt));
+ }
+ else
+ {
+ return ExprOrStmt::create_error ();
+ }
}
// return expression