public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6169] gccrs: fix ICE on missing closing paren
@ 2023-02-21 11:56 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2023-02-21 11:56 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:570415e75c42a6346724859d12f38ec3faa9edd8

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

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-21 11:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-21 11:56 [gcc r13-6169] gccrs: fix ICE on missing closing paren Arthur Cohen

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).