From: Lucas Ly Ba Date: Mon, 13 Oct 2025 11:01:54 +0000 (+0000) Subject: gccrs: fix ICE on missing pattern in while loop X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb88b7b6dc7c65955b7349caf5e6d458341921c8;p=thirdparty%2Fgcc.git gccrs: fix ICE on missing pattern in while loop Adds a proper check for missing patterns in while expressions. Fixes Rust-GCC#4162 gcc/rust/ChangeLog: * parse/rust-parse-impl.h(Parser::parse_while_let_loop_expr): Add check for missing pattern. gcc/testsuite/ChangeLog: * rust/compile/issue-4162.rs: New test. Signed-off-by: Lucas Ly Ba --- diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 62831ebbf10..64554f5e9e4 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -8234,7 +8234,14 @@ Parser::parse_while_let_loop_expr ( // parse predicate patterns std::vector> predicate_patterns = parse_match_arm_patterns (EQUAL); - // TODO: have to ensure that there is at least 1 pattern? + // ensure that there is at least 1 pattern + if (predicate_patterns.empty ()) + { + Error error (lexer.peek_token ()->get_locus (), + "should be at least 1 pattern"); + add_error (std::move (error)); + return nullptr; + } if (!skip_token (EQUAL)) { diff --git a/gcc/testsuite/rust/compile/issue-4162.rs b/gcc/testsuite/rust/compile/issue-4162.rs new file mode 100644 index 00000000000..c82bac611d3 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4162.rs @@ -0,0 +1,9 @@ +pub fn main() { + while let = 5 + // { dg-error "should be at least 1 pattern" "" { target *-*-* } .-1 } + // { dg-error "failed to parse statement or expression in block expression" "" { target *-*-* } .-2 } + // { dg-error "unrecognised token .=. for start of item" "" { target *-*-* } .-3 } + // { dg-error "failed to parse item in crate" "" { target *-*-* } .-4 } + {} +} +