]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: Fix segv when handling invalid array capacities
authorPhilip Herron <herron.philip@googlemail.com>
Sun, 31 Aug 2025 21:57:05 +0000 (22:57 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:59:07 +0000 (20:59 +0100)
commit1422fa61b44963f0b3ed19e110bd7ccbddd311ce
treee453acfe310baa603f61271f23ca7aaefa2d8392
parent735ac41b5c3c0bd2cf2bfa63292221e53f85ddb7
gccrs: Fix segv when handling invalid array capacities

We need to catch the error node for the array capacity and return early.
Otherwise we try to const evaluate something thats just silly. Also
when compiling array expressions we can simply reuse the array capacity
expression we already have cons folded.

Fixes Rust-GCC#3965

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: add assertions for context peeks
* backend/rust-compile-expr.cc (CompileExpr::visit): check for valid loop context
(CompileExpr::array_copied_expr): just reuse array tyty capacity value
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): catch error

gcc/testsuite/ChangeLog:

* rust/compile/issue-3965-1.rs: New test.
* rust/compile/issue-3965-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-context.h
gcc/rust/backend/rust-compile-expr.cc
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/testsuite/rust/compile/issue-3965-1.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/issue-3965-2.rs [new file with mode: 0644]