From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 6673B3858032; Tue, 21 Feb 2023 11:56:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6673B3858032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676980594; bh=DIfvozgit86FqTX4laDE3otTx7381CgOHKGrE/4SVg8=; h=From:To:Subject:Date:From; b=mfSgwGHTH1fE/H2oyqBrO/3NKyxyAThmQO/yaDN0ILyB4TA+/PxYxjLF61FL5vq68 rHIe5AjPBX6ptSK8d0y96CNGqIiATb9gehib/ZOD3KLBlvO9Q2Sr4v/QL5v/TcPfD6 QmtpLxQ+EMjoykCrJobWJvDeCz+R60yaARQoTT7s= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6169] gccrs: fix ICE on missing closing paren X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Git-Refname: refs/heads/master X-Git-Oldrev: ab6d8ad3f5957c88208cac2b397ac070d341db1a X-Git-Newrev: 570415e75c42a6346724859d12f38ec3faa9edd8 Message-Id: <20230221115634.6673B3858032@sourceware.org> Date: Tue, 21 Feb 2023 11:56:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:570415e75c42a6346724859d12f38ec3faa9edd8 commit r13-6169-g570415e75c42a6346724859d12f38ec3faa9edd8 Author: Marc Poulhiès Date: Fri Oct 7 18:48:36 2022 +0200 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 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. Diff: --- gcc/rust/parse/rust-parse-impl.h | 15 +++++++++++---- gcc/testsuite/rust/compile/missing_closing_paren.rs | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 72207a1bc22..a4a912f8c1d 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -11738,10 +11738,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 00000000000..895c3133c3b --- /dev/null +++ b/gcc/testsuite/rust/compile/missing_closing_paren.rs @@ -0,0 +1,3 @@ +fn foo() { + (""; // { dg-error "unexpected token .*" } +}