diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-01-07 12:32:43 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2025-01-07 16:33:05 +0000 |
commit | 5bccf14d99253f3f39f12701b8a0066ed95f2e59 (patch) | |
tree | 39b966fa142395b2d3e94e9c0f1c18a536b8f519 /gcc/rust | |
parent | fa6747f326dfbf883292d5599c7d926cbf6c62e3 (diff) | |
download | gcc-5bccf14d99253f3f39f12701b8a0066ed95f2e59.zip gcc-5bccf14d99253f3f39f12701b8a0066ed95f2e59.tar.gz gcc-5bccf14d99253f3f39f12701b8a0066ed95f2e59.tar.bz2 |
gccrs: fix ICE in borrows to invalid expressions
We need to check if the borrowed value is valid before creating the
reference type. Otherwise this will lead to an ICE.
Fixes Rust-GCC#3140
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): check for error
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): likewise and remove debug error
gcc/testsuite/ChangeLog:
* rust/compile/issue-3046.rs: remove old error message
* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3140.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.cc | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-call.cc | 9 |
2 files changed, 4 insertions, 7 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 7daa271..9a075c0 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1366,6 +1366,8 @@ void TypeCheckExpr::visit (HIR::BorrowExpr &expr) { TyTy::BaseType *resolved_base = TypeCheckExpr::Resolve (expr.get_expr ()); + if (resolved_base->is<TyTy::ErrorType> ()) + return; // In Rust this is valid because of DST's // diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index dbb0379..75cf58f 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -140,13 +140,8 @@ TypeCheckCallExpr::visit (FnType &type) { location_t arg_locus = argument->get_locus (); auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (*argument); - if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) - { - rust_error_at ( - argument->get_locus (), - "failed to resolve type for argument expr in CallExpr"); - return; - } + if (argument_expr_tyty->is<TyTy::ErrorType> ()) + return; // it might be a variadic function if (i < type.num_params ()) |