aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-11-25 15:01:01 +0000
committerGitHub <noreply@github.com>2021-11-25 15:01:01 +0000
commit295f0ae16613b44c13a15ae5ada080761b62ff54 (patch)
tree0b3be7ed250e3cd25605ee7ce656b385c1c0d6b5 /gcc/rust/backend
parentbdfe6abe2b11e2ddad0b8c8a92b57297fdd73f6b (diff)
parente7e65bbdf3a06a7d00ed7da4ff8ebb16031ed6c3 (diff)
downloadgcc-295f0ae16613b44c13a15ae5ada080761b62ff54.zip
gcc-295f0ae16613b44c13a15ae5ada080761b62ff54.tar.gz
gcc-295f0ae16613b44c13a15ae5ada080761b62ff54.tar.bz2
Merge #817
817: Remove bad mutability check pass r=philberty a=philberty This was an initial pass to try and ensure all assignments were valid with respect to the binding mutability. This pass cannot be done at the name resolution level and in rustc is achieved on mir as part of the borrow checker. This patch removes this pass and associated test cases. This set of patches also adds support for indirection around array index expressions. Fixes #815 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 2bf969b..46d501a 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -390,10 +390,32 @@ public:
void visit (HIR::ArrayIndexExpr &expr) override
{
- tree array = CompileExpr::Compile (expr.get_array_expr (), ctx);
+ tree array_reference = CompileExpr::Compile (expr.get_array_expr (), ctx);
tree index = CompileExpr::Compile (expr.get_index_expr (), ctx);
+
+ // lets check if the array is a reference type then we can add an
+ // indirection if required
+ TyTy::BaseType *array_expr_ty = nullptr;
+ bool ok = ctx->get_tyctx ()->lookup_type (
+ expr.get_array_expr ()->get_mappings ().get_hirid (), &array_expr_ty);
+ rust_assert (ok);
+
+ // do we need to add an indirect reference
+ if (array_expr_ty->get_kind () == TyTy::TypeKind::REF)
+ {
+ TyTy::ReferenceType *r
+ = static_cast<TyTy::ReferenceType *> (array_expr_ty);
+ TyTy::BaseType *tuple_type = r->get_base ();
+ tree array_tyty = TyTyResolveCompile::compile (ctx, tuple_type);
+
+ array_reference
+ = ctx->get_backend ()->indirect_expression (array_tyty,
+ array_reference, true,
+ expr.get_locus ());
+ }
+
translated
- = ctx->get_backend ()->array_index_expression (array, index,
+ = ctx->get_backend ()->array_index_expression (array_reference, index,
expr.get_locus ());
}