From d4c07a9b47c7063a4e79b6b45edccd0e79249605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Fri, 7 Oct 2022 18:48:36 +0200 Subject: fix ICE on missing closing paren MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- gcc/rust/parse/rust-parse-impl.h | 15 +++++++++++---- gcc/testsuite/rust/compile/missing_closing_paren.rs | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/rust/compile/missing_closing_paren.rs (limited to 'gcc') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index c4cfbe2..4ebdcf0 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -11728,10 +11728,17 @@ Parser::parse_stmt_or_expr_without_block () // must be expression statement lexer.skip_token (); - std::unique_ptr stmt ( - new AST::ExprStmtWithoutBlock (std::move (expr), - t->get_locus ())); - return ExprOrStmt (std::move (stmt)); + if (expr) + { + std::unique_ptr stmt ( + new AST::ExprStmtWithoutBlock (std::move (expr), + t->get_locus ())); + return ExprOrStmt (std::move (stmt)); + } + else + { + return ExprOrStmt::create_error (); + } } // return expression diff --git a/gcc/testsuite/rust/compile/missing_closing_paren.rs b/gcc/testsuite/rust/compile/missing_closing_paren.rs new file mode 100644 index 0000000..895c313 --- /dev/null +++ b/gcc/testsuite/rust/compile/missing_closing_paren.rs @@ -0,0 +1,3 @@ +fn foo() { + (""; // { dg-error "unexpected token .*" } +} -- cgit v1.1