diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-03-27 12:04:41 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-31 21:07:16 +0200 |
commit | 4c2b0c1d885fd01d20f252155df1578278548367 (patch) | |
tree | 7b958be04479189e8768719b0360a30774242c09 /gcc/rust/backend | |
parent | 0b522745670e83ee4b5af0782982743b3f715c30 (diff) | |
download | gcc-4c2b0c1d885fd01d20f252155df1578278548367.zip gcc-4c2b0c1d885fd01d20f252155df1578278548367.tar.gz gcc-4c2b0c1d885fd01d20f252155df1578278548367.tar.bz2 |
gccrs: Fix ICE when compiling block expressions in array capacity
We need to reuse the existing compile_constant_item helper which handles
the case if this is a simple expression, fn-call or a block expression.
The patch extracts out this helper as a static method so this can be used
in more places.
Fixes Rust-GCC#3566
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::address_expression): new helper constexpr
* backend/rust-compile-base.h: prototype
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): call constexpr helper
gcc/testsuite/ChangeLog:
* rust/compile/issue-3566-1.rs: New test.
* rust/compile/issue-3566-2.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-base.cc | 12 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-base.h | 6 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-type.cc | 12 |
3 files changed, 29 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index bcc7fc4..b477113 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -561,6 +561,18 @@ HIRCompileBase::address_expression (tree expr, location_t location) } tree +HIRCompileBase::compile_constant_expr ( + Context *ctx, HirId coercion_id, TyTy::BaseType *resolved_type, + TyTy::BaseType *expected_type, const Resolver::CanonicalPath &canonical_path, + HIR::Expr &const_value_expr, location_t locus, location_t expr_locus) +{ + HIRCompileBase c (ctx); + return c.compile_constant_item (coercion_id, resolved_type, expected_type, + canonical_path, const_value_expr, locus, + expr_locus); +} + +tree HIRCompileBase::indirect_expression (tree expr, location_t locus) { if (expr == error_mark_node) diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index 9328a7f..109c853 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -31,6 +31,12 @@ public: static tree address_expression (tree expr, location_t locus); + static tree compile_constant_expr ( + Context *ctx, HirId coercion_id, TyTy::BaseType *resolved_type, + TyTy::BaseType *expected_type, + const Resolver::CanonicalPath &canonical_path, HIR::Expr &const_value_expr, + location_t locus, location_t expr_locus); + protected: HIRCompileBase (Context *ctx) : ctx (ctx) {} diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index d8af1d1..7354801 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -456,7 +456,17 @@ TyTyResolveCompile::visit (const TyTy::ArrayType &type) = TyTyResolveCompile::compile (ctx, type.get_element_type ()); ctx->push_const_context (); - tree capacity_expr = CompileExpr::Compile (type.get_capacity_expr (), ctx); + + HIR::Expr &hir_capacity_expr = type.get_capacity_expr (); + TyTy::BaseType *capacity_expr_ty = nullptr; + bool ok = ctx->get_tyctx ()->lookup_type ( + hir_capacity_expr.get_mappings ().get_hirid (), &capacity_expr_ty); + rust_assert (ok); + tree capacity_expr = HIRCompileBase::compile_constant_expr ( + ctx, hir_capacity_expr.get_mappings ().get_hirid (), capacity_expr_ty, + capacity_expr_ty, Resolver::CanonicalPath::create_empty (), + hir_capacity_expr, type.get_locus (), hir_capacity_expr.get_locus ()); + ctx->pop_const_context (); tree folded_capacity_expr = fold_expr (capacity_expr); |