From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 97AC83850228; Wed, 12 Oct 2022 10:14:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97AC83850228 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665569684; bh=DzMJER6IgNeezK2OWNsmmYjlHMWeM+7pzfD3aDdgy0I=; h=From:To:Subject:Date:From; b=OLC9svFi4/CJ8zIGV+bqrBeh1IkxVmna3HYWORyN8HdS0Eyde19rYJ4HLqJE1XUtC fet8VkCDIY7o+DiL66T6xW1UD7Cr8fBgp11uAuhft/7gSUSigDSpxyH560wtkJMZ4J uXl4FA0ySzjhFxnyZHIPCByoXmQOruMBLmCx4R2A= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] 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/devel/rust/master X-Git-Oldrev: 06fe912b70bc21dd11e7279e29200431a5b50aa2 X-Git-Newrev: d4c07a9b47c7063a4e79b6b45edccd0e79249605 Message-Id: <20221012101444.97AC83850228@sourceware.org> Date: Wed, 12 Oct 2022 10:14:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d4c07a9b47c7063a4e79b6b45edccd0e79249605 commit d4c07a9b47c7063a4e79b6b45edccd0e79249605 Author: Marc Poulhiès Date: Fri Oct 7 18:48:36 2022 +0200 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 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 c4cfbe2cce9..4ebdcf04f14 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 00000000000..895c3133c3b --- /dev/null +++ b/gcc/testsuite/rust/compile/missing_closing_paren.rs @@ -0,0 +1,3 @@ +fn foo() { + (""; // { dg-error "unexpected token .*" } +}