aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-10-10 16:46:57 +0000
committerGitHub <noreply@github.com>2022-10-10 16:46:57 +0000
commit3e7320510e7bb774295ecbd8089a9f51d6475959 (patch)
tree945d1ce4d8a45e0ec32912c8b23883cc02ebb578 /gcc
parent06fe912b70bc21dd11e7279e29200431a5b50aa2 (diff)
parentd4c07a9b47c7063a4e79b6b45edccd0e79249605 (diff)
downloadgcc-3e7320510e7bb774295ecbd8089a9f51d6475959.zip
gcc-3e7320510e7bb774295ecbd8089a9f51d6475959.tar.gz
gcc-3e7320510e7bb774295ecbd8089a9f51d6475959.tar.bz2
Merge #1574
1574: fix ICE on missing closing paren r=dkm a=dkm 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> Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h15
-rw-r--r--gcc/testsuite/rust/compile/missing_closing_paren.rs3
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 c4cfbe2..4ebdcf0 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 0000000..895c313
--- /dev/null
+++ b/gcc/testsuite/rust/compile/missing_closing_paren.rs
@@ -0,0 +1,3 @@
+fn foo() {
+ (""; // { dg-error "unexpected token .*" }
+}