public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] fix ICE on missing closing paren
Date: Wed, 12 Oct 2022 10:14:44 +0000 (GMT)	[thread overview]
Message-ID: <20221012101444.97AC83850228@sourceware.org> (raw)

https://gcc.gnu.org/g:d4c07a9b47c7063a4e79b6b45edccd0e79249605

commit d4c07a9b47c7063a4e79b6b45edccd0e79249605
Author: Marc Poulhiès <dkm@kataplop.net>
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 <dkm@kataplop.net>

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<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
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 .*" }
+}

                 reply	other threads:[~2022-10-12 10:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221012101444.97AC83850228@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).