diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-05-02 21:26:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 21:26:10 +0000 |
commit | ca722fe423bdd8c7895a40aac0410b2646917805 (patch) | |
tree | 52ca965213514c45d7143acff72d9d21f090b4e6 /gcc/rust/backend/rust-compile-expr.cc | |
parent | 5aec7cbfa560440801dfd0b26e408ab6fb692ed6 (diff) | |
parent | 7e576d70b6a1065bf31c37380a8e39354d961cd6 (diff) | |
download | gcc-ca722fe423bdd8c7895a40aac0410b2646917805.zip gcc-ca722fe423bdd8c7895a40aac0410b2646917805.tar.gz gcc-ca722fe423bdd8c7895a40aac0410b2646917805.tar.bz2 |
Merge #1197
1197: Support recursive coercion sites r=philberty a=philberty
There are two changes are part of this PR one where we update the address_expression
helper to take a ptrtype tree. Since the default build_address_expr_loc was automatically
building a pointer type of the TREE_TYPE of the operand which is not correct since we
sometimes want REFERENCE_TYPES instead of POINTER_TYPES.
The 2nd commit enhances the coercion_site code to recursively walk the tree and their
types to handle coercions to dyn traits or do array bounds checking etc. This gets rid of
the get_root hack used and cleans up the code in general.
Fixes #1146
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index edeea8d..4225263 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -123,7 +123,14 @@ void CompileExpr::visit (HIR::BorrowExpr &expr) { tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx); - translated = address_expression (main_expr, expr.get_locus ()); + + TyTy::BaseType *tyty = nullptr; + if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), + &tyty)) + return; + + tree ptrtype = TyTyResolveCompile::compile (ctx, tyty); + translated = address_expression (main_expr, ptrtype, expr.get_locus ()); } void @@ -670,17 +677,6 @@ CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn, = ctx->get_backend ()->convert_expression (expected_fntype, fn_vtable_access, expr_locus); - fncontext fnctx = ctx->peek_fn (); - tree enclosing_scope = ctx->peek_enclosing_scope (); - bool is_address_taken = false; - tree ret_var_stmt = NULL_TREE; - Bvariable *fn_convert_expr_tmp - = ctx->get_backend ()->temporary_variable (fnctx.fndecl, enclosing_scope, - expected_fntype, fn_convert_expr, - is_address_taken, expr_locus, - &ret_var_stmt); - ctx->add_statement (ret_var_stmt); - std::vector<tree> args; args.push_back (self_argument); for (auto &argument : arguments) @@ -689,10 +685,7 @@ CompileExpr::compile_dyn_dispatch_call (const TyTy::DynamicObjectType *dyn, args.push_back (compiled_expr); } - tree fn_expr - = ctx->get_backend ()->var_expression (fn_convert_expr_tmp, expr_locus); - - return ctx->get_backend ()->call_expression (fn_expr, args, nullptr, + return ctx->get_backend ()->call_expression (fn_convert_expr, args, nullptr, expr_locus); } @@ -707,7 +700,8 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref, tree fn = NULL_TREE; if (ctx->lookup_function_decl (fntype->get_ty_ref (), &fn)) { - return address_expression (fn, expr_locus); + return address_expression (fn, build_pointer_type (TREE_TYPE (fn)), + expr_locus); } // Now we can try and resolve the address since this might be a forward @@ -983,7 +977,8 @@ CompileExpr::compile_string_literal (const HIR::LiteralExpr &expr, auto base = ctx->get_backend ()->string_constant_expression ( literal_value.as_string ()); - return address_expression (base, expr.get_locus ()); + return address_expression (base, build_pointer_type (TREE_TYPE (base)), + expr.get_locus ()); } tree @@ -1016,7 +1011,8 @@ CompileExpr::compile_byte_string_literal (const HIR::LiteralExpr &expr, vals, expr.get_locus ()); - return address_expression (constructed, expr.get_locus ()); + return address_expression (constructed, build_pointer_type (array_type), + expr.get_locus ()); } tree @@ -1233,8 +1229,11 @@ HIRCompileBase::resolve_adjustements ( return error_mark_node; case Resolver::Adjustment::AdjustmentType::IMM_REF: - case Resolver::Adjustment::AdjustmentType::MUT_REF: - e = address_expression (e, locus); + case Resolver::Adjustment::AdjustmentType::MUT_REF: { + tree ptrtype + = TyTyResolveCompile::compile (ctx, adjustment.get_expected ()); + e = address_expression (e, ptrtype, locus); + } break; case Resolver::Adjustment::AdjustmentType::DEREF: @@ -1280,7 +1279,10 @@ HIRCompileBase::resolve_deref_adjustment (Resolver::Adjustment &adjustment, != Resolver::Adjustment::AdjustmentType::ERROR; if (needs_borrow) { - adjusted_argument = address_expression (expression, locus); + adjusted_argument + = address_expression (expression, + build_reference_type (TREE_TYPE (expression)), + locus); } // make the call @@ -1316,7 +1318,9 @@ HIRCompileBase::resolve_unsized_adjustment (Resolver::Adjustment &adjustment, = TyTyResolveCompile::compile (ctx, adjustment.get_expected ()); // make a constructor for this - tree data = address_expression (expression, locus); + tree data + = address_expression (expression, + build_reference_type (TREE_TYPE (expression)), locus); // fetch the size from the domain tree domain = TYPE_DOMAIN (expr_type); @@ -1414,7 +1418,8 @@ CompileExpr::visit (HIR::IdentifierExpr &expr) else if (ctx->lookup_function_decl (ref, &fn)) { TREE_USED (fn) = 1; - translated = address_expression (fn, expr.get_locus ()); + translated = address_expression (fn, build_pointer_type (TREE_TYPE (fn)), + expr.get_locus ()); } else if (ctx->lookup_var_decl (ref, &var)) { |