From 94e53f8e55e93da8db3d948c3f16d23b7c4ba7a6 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 3 Aug 2022 11:54:54 +0100 Subject: Refactor indirect_expression from the gcc-backend wrapper This brings out the indirect expression out of our gcc wrapper, it also just simplifies down to the normal build_indirect_expr_loc calls. Which does not require specifiying the type since we can reuse TREE_TYPE. This also simplifies the address_expression to just address_expr_with_loc and grabs the type from TREE_TYPE as well. --- gcc/rust/backend/rust-compile-base.cc | 14 ++++- gcc/rust/backend/rust-compile-base.h | 4 +- gcc/rust/backend/rust-compile-expr.cc | 82 +++++---------------------- gcc/rust/backend/rust-compile-expr.h | 14 +---- gcc/rust/backend/rust-compile-extern.h | 9 +-- gcc/rust/backend/rust-compile-implitem.cc | 10 +--- gcc/rust/backend/rust-compile-item.cc | 9 +-- gcc/rust/backend/rust-compile-resolve-path.cc | 6 +- gcc/rust/backend/rust-compile.cc | 27 ++------- 9 files changed, 44 insertions(+), 131 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 28f3941..a640a48 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -411,7 +411,7 @@ HIRCompileBase::mark_addressable (tree exp, Location locus) } tree -HIRCompileBase::address_expression (tree expr, tree ptrtype, Location location) +HIRCompileBase::address_expression (tree expr, Location location) { if (expr == error_mark_node) return error_mark_node; @@ -419,8 +419,16 @@ HIRCompileBase::address_expression (tree expr, tree ptrtype, Location location) if (!mark_addressable (expr, location)) return error_mark_node; - return build_fold_addr_expr_with_type_loc (location.gcc_location (), expr, - ptrtype); + return build_fold_addr_expr_loc (location.gcc_location (), expr); +} + +tree +HIRCompileBase::indirect_expression (tree expr, Location locus) +{ + if (expr == error_mark_node) + return error_mark_node; + + return build_fold_indirect_ref_loc (locus.gcc_location (), expr); } std::vector diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index f993d06..aad0da3 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -101,7 +101,9 @@ protected: static void setup_abi_options (tree fndecl, ABI abi); - static tree address_expression (tree expr, tree ptrtype, Location locus); + static tree address_expression (tree expr, Location locus); + + static tree indirect_expression (tree expr, Location locus); static bool mark_addressable (tree, Location); diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 7aa691e..92c224c 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -134,8 +134,7 @@ CompileExpr::visit (HIR::BorrowExpr &expr) &tyty)) return; - tree ptrtype = TyTyResolveCompile::compile (ctx, tyty); - translated = address_expression (main_expr, ptrtype, expr.get_locus ()); + translated = address_expression (main_expr, expr.get_locus ()); } void @@ -175,10 +174,7 @@ CompileExpr::visit (HIR::DereferenceExpr &expr) return; } - bool known_valid = true; - translated - = ctx->get_backend ()->indirect_expression (expected_type, main_expr, - known_valid, expr.get_locus ()); + translated = indirect_expression (main_expr, expr.get_locus ()); } // Helper for sort_tuple_patterns. @@ -1111,15 +1107,7 @@ CompileExpr::get_fn_addr_from_dyn (const TyTy::DynamicObjectType *dyn, // get any indirection sorted out if (receiver->get_kind () == TyTy::TypeKind::REF) { - TyTy::ReferenceType *r = static_cast (receiver); - auto indirect_ty = r->get_base (); - tree indrect_compiled_tyty - = TyTyResolveCompile::compile (ctx, indirect_ty); - - tree indirect - = ctx->get_backend ()->indirect_expression (indrect_compiled_tyty, - receiver_ref, true, - expr_locus); + tree indirect = indirect_expression (receiver_ref, expr_locus); receiver_ref = indirect; } @@ -1149,17 +1137,8 @@ CompileExpr::get_receiver_from_dyn (const TyTy::DynamicObjectType *dyn, { // get any indirection sorted out if (receiver->get_kind () == TyTy::TypeKind::REF) - { - TyTy::ReferenceType *r = static_cast (receiver); - auto indirect_ty = r->get_base (); - tree indrect_compiled_tyty - = TyTyResolveCompile::compile (ctx, indirect_ty); - - tree indirect - = ctx->get_backend ()->indirect_expression (indrect_compiled_tyty, - receiver_ref, true, - expr_locus); + tree indirect = indirect_expression (receiver_ref, expr_locus); receiver_ref = indirect; } @@ -1179,8 +1158,7 @@ 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, build_pointer_type (TREE_TYPE (fn)), - expr_locus); + return address_expression (fn, expr_locus); } // Now we can try and resolve the address since this might be a forward @@ -1440,8 +1418,7 @@ CompileExpr::compile_string_literal (const HIR::LiteralExpr &expr, auto base = ctx->get_backend ()->string_constant_expression ( literal_value.as_string ()); - tree data = address_expression (base, build_pointer_type (TREE_TYPE (base)), - expr.get_locus ()); + tree data = address_expression (base, expr.get_locus ()); TyTy::BaseType *usize = nullptr; bool ok = ctx->get_tyctx ()->lookup_builtin ("usize", &usize); @@ -1487,8 +1464,7 @@ CompileExpr::compile_byte_string_literal (const HIR::LiteralExpr &expr, vals, expr.get_locus ()); - return address_expression (constructed, build_pointer_type (array_type), - expr.get_locus ()); + return address_expression (constructed, expr.get_locus ()); } tree @@ -1734,10 +1710,7 @@ HIRCompileBase::resolve_adjustements ( case Resolver::Adjustment::AdjustmentType::MUT_REF: { if (!SLICE_TYPE_P (TREE_TYPE (e))) { - tree ptrtype - = TyTyResolveCompile::compile (ctx, - adjustment.get_expected ()); - e = address_expression (e, ptrtype, locus); + e = address_expression (e, locus); } } break; @@ -1785,10 +1758,7 @@ HIRCompileBase::resolve_deref_adjustment (Resolver::Adjustment &adjustment, != Resolver::Adjustment::AdjustmentType::ERROR; if (needs_borrow) { - adjusted_argument - = address_expression (expression, - build_reference_type (TREE_TYPE (expression)), - locus); + adjusted_argument = address_expression (expression, locus); } // make the call @@ -1800,12 +1770,7 @@ tree HIRCompileBase::resolve_indirection_adjustment ( Resolver::Adjustment &adjustment, tree expression, Location locus) { - tree expected_type - = TyTyResolveCompile::compile (ctx, adjustment.get_expected ()); - - return ctx->get_backend ()->indirect_expression (expected_type, expression, - true, /* known_valid*/ - locus); + return indirect_expression (expression, locus); } tree @@ -1824,9 +1789,7 @@ HIRCompileBase::resolve_unsized_adjustment (Resolver::Adjustment &adjustment, = TyTyResolveCompile::compile (ctx, adjustment.get_expected ()); // make a constructor for this - tree data - = address_expression (expression, - build_reference_type (TREE_TYPE (expression)), locus); + tree data = address_expression (expression, locus); // fetch the size from the domain tree domain = TYPE_DOMAIN (expr_type); @@ -1919,8 +1882,7 @@ CompileExpr::visit (HIR::IdentifierExpr &expr) else if (ctx->lookup_function_decl (ref, &fn)) { TREE_USED (fn) = 1; - translated = address_expression (fn, build_pointer_type (TREE_TYPE (fn)), - expr.get_locus ()); + translated = address_expression (fn, expr.get_locus ()); } else if (ctx->lookup_var_decl (ref, &var)) { @@ -2091,20 +2053,10 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr) return; } - // lookup the expected type for this expression - TyTy::BaseType *tyty = nullptr; - bool ok - = ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), - &tyty); - rust_assert (ok); - tree expected_type = TyTyResolveCompile::compile (ctx, tyty); - // rust deref always returns a reference from this overload then we can // actually do the indirection translated - = ctx->get_backend ()->indirect_expression (expected_type, - operator_overload_call, - true, expr.get_locus ()); + = indirect_expression (operator_overload_call, expr.get_locus ()); return; } @@ -2118,14 +2070,8 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr) // do we need to add an indirect reference if (array_expr_ty->get_kind () == TyTy::TypeKind::REF) { - TyTy::ReferenceType *r - = static_cast (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 ()); + = indirect_expression (array_reference, expr.get_locus ()); } translated diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 48a516a..bc14239 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -53,14 +53,7 @@ public: // do we need to add an indirect reference if (tuple_expr_ty->get_kind () == TyTy::TypeKind::REF) { - TyTy::ReferenceType *r - = static_cast (tuple_expr_ty); - TyTy::BaseType *tuple_type = r->get_base (); - tree tuple_tyty = TyTyResolveCompile::compile (ctx, tuple_type); - - tree indirect - = ctx->get_backend ()->indirect_expression (tuple_tyty, receiver_ref, - true, expr.get_locus ()); + tree indirect = indirect_expression (receiver_ref, expr.get_locus ()); receiver_ref = indirect; } @@ -552,10 +545,7 @@ public: &field_index); rust_assert (ok); - tree adt_tyty = TyTyResolveCompile::compile (ctx, adt); - tree indirect - = ctx->get_backend ()->indirect_expression (adt_tyty, receiver_ref, - true, expr.get_locus ()); + tree indirect = indirect_expression (receiver_ref, expr.get_locus ()); receiver_ref = indirect; } diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h index 4355e4a..45a507e 100644 --- a/gcc/rust/backend/rust-compile-extern.h +++ b/gcc/rust/backend/rust-compile-extern.h @@ -110,10 +110,7 @@ public: if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup, fntype->get_id (), fntype)) { - reference - = address_expression (lookup, build_pointer_type (TREE_TYPE (lookup)), - ref_locus); - + reference = address_expression (lookup, ref_locus); return; } @@ -155,9 +152,7 @@ public: ctx->insert_function_decl (fntype, fndecl); - reference - = address_expression (fndecl, build_pointer_type (TREE_TYPE (fndecl)), - ref_locus); + reference = address_expression (fndecl, ref_locus); } private: diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc index 735dede..d0f70a7 100644 --- a/gcc/rust/backend/rust-compile-implitem.cc +++ b/gcc/rust/backend/rust-compile-implitem.cc @@ -67,10 +67,8 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func) { ctx->insert_function_decl (fntype, lookup); } - reference - = address_expression (lookup, - build_pointer_type (TREE_TYPE (lookup)), - ref_locus); + + reference = address_expression (lookup, ref_locus); return; } } @@ -96,9 +94,7 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func) func.get_outer_attrs (), func.get_locus (), func.get_block_expr ().get (), canonical_path, fntype, function.has_return_type ()); - reference - = address_expression (fndecl, build_pointer_type (TREE_TYPE (fndecl)), - ref_locus); + reference = address_expression (fndecl, ref_locus); } } // namespace Compile diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc index 1f2e479..ceba51c 100644 --- a/gcc/rust/backend/rust-compile-item.cc +++ b/gcc/rust/backend/rust-compile-item.cc @@ -144,10 +144,7 @@ CompileItem::visit (HIR::Function &function) ctx->insert_function_decl (fntype, lookup); } - reference - = address_expression (lookup, - build_pointer_type (TREE_TYPE (lookup)), - ref_locus); + reference = address_expression (lookup, ref_locus); return; } } @@ -171,9 +168,7 @@ CompileItem::visit (HIR::Function &function) function.get_outer_attrs (), function.get_locus (), function.get_definition ().get (), canonical_path, fntype, function.has_function_return_type ()); - reference - = address_expression (fndecl, build_pointer_type (TREE_TYPE (fndecl)), - ref_locus); + reference = address_expression (fndecl, ref_locus); } void diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index b5bfa3c..8c1b7ef 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -129,16 +129,14 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment, if (ctx->lookup_function_decl (fntype->get_ty_ref (), &fn)) { TREE_USED (fn) = 1; - return address_expression (fn, build_pointer_type (TREE_TYPE (fn)), - expr_locus); + return address_expression (fn, expr_locus); } else if (fntype->get_abi () == ABI::INTRINSIC) { Intrinsics compile (ctx); fn = compile.compile (fntype); TREE_USED (fn) = 1; - return address_expression (fn, build_pointer_type (TREE_TYPE (fn)), - expr_locus); + return address_expression (fn, expr_locus); } } diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 9bcd01c..4f17fa6 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -225,20 +225,14 @@ HIRCompileBase::coercion_site (tree rvalue, const TyTy::BaseType *rval, const TyTy::ReferenceType *act = static_cast (actual); - tree expected_type = TyTyResolveCompile::compile (ctx, act->get_base ()); - tree deref_rvalue - = ctx->get_backend ()->indirect_expression (expected_type, rvalue, - false /*known_valid*/, - rvalue_locus); + tree deref_rvalue = indirect_expression (rvalue, rvalue_locus); tree coerced = coercion_site (deref_rvalue, act->get_base (), exp->get_base (), lvalue_locus, rvalue_locus); if (exp->is_dyn_object () && SLICE_TYPE_P (TREE_TYPE (coerced))) return coerced; - return address_expression (coerced, - build_reference_type (TREE_TYPE (coerced)), - rvalue_locus); + return address_expression (coerced, rvalue_locus); } else if (expected->get_kind () == TyTy::TypeKind::POINTER) { @@ -258,14 +252,12 @@ HIRCompileBase::coercion_site (tree rvalue, const TyTy::BaseType *rval, = static_cast (expected); TyTy::BaseType *actual_base = nullptr; - tree expected_type = error_mark_node; if (actual->get_kind () == TyTy::TypeKind::REF) { const TyTy::ReferenceType *act = static_cast (actual); actual_base = act->get_base (); - expected_type = TyTyResolveCompile::compile (ctx, act->get_base ()); } else if (actual->get_kind () == TyTy::TypeKind::POINTER) { @@ -273,22 +265,16 @@ HIRCompileBase::coercion_site (tree rvalue, const TyTy::BaseType *rval, = static_cast (actual); actual_base = act->get_base (); - expected_type = TyTyResolveCompile::compile (ctx, act->get_base ()); } rust_assert (actual_base != nullptr); - tree deref_rvalue - = ctx->get_backend ()->indirect_expression (expected_type, rvalue, - false /*known_valid*/, - rvalue_locus); + tree deref_rvalue = indirect_expression (rvalue, rvalue_locus); tree coerced = coercion_site (deref_rvalue, actual_base, exp->get_base (), lvalue_locus, rvalue_locus); if (exp->is_dyn_object () && SLICE_TYPE_P (TREE_TYPE (coerced))) return coerced; - return address_expression (coerced, - build_pointer_type (TREE_TYPE (coerced)), - rvalue_locus); + return address_expression (coerced, rvalue_locus); } else if (expected->get_kind () == TyTy::TypeKind::ARRAY) { @@ -350,10 +336,7 @@ HIRCompileBase::coerce_to_dyn_object (tree compiled_ref, tree address_of_compiled_ref = null_pointer_node; if (!actual->is_unit ()) - address_of_compiled_ref - = address_expression (compiled_ref, - build_pointer_type (TREE_TYPE (compiled_ref)), - locus); + address_of_compiled_ref = address_expression (compiled_ref, locus); std::vector vtable_ctor_elems; std::vector vtable_ctor_idx; -- cgit v1.1 From 405d9f1d135771015199546cd1c224ba589ab48d Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 3 Aug 2022 11:58:06 +0100 Subject: Fix ICE with duplicate hirid on autoderef coercion site mappings Imagine the call expression: Foo(a+b) But the a+b is an operator overload of the assignment operation. We store the autoderef coercions on the HIR id of the plus_expression here which is going to conflict with the id used to store the autoderef coercions the argument a+b. So this patch changes that all autoderef coercions store the autoderef for the implicit method call on the hirid of the lvalue hirid which in this case is 'a'. This means we won't conflict and cause an ICE in this case. --- gcc/rust/backend/rust-compile-expr.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 92c224c..35861c1 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1285,7 +1285,7 @@ CompileExpr::resolve_operator_overload ( // lookup the autoderef mappings std::vector *adjustments = nullptr; ok = ctx->get_tyctx ()->lookup_autoderef_mappings ( - expr.get_mappings ().get_hirid (), &adjustments); + expr.get_lvalue_mappings ().get_hirid (), &adjustments); rust_assert (ok); // apply adjustments for the fn call -- cgit v1.1 From 79d0f29464fc0aa68af7b317964aff4bc35af59a Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 4 Aug 2022 16:13:52 +0100 Subject: Fix ICE in audodref mappings when argument is a method call Similar to the fix in 405d9f1d135771015199546cd1c224ba589ab48d when we have arguments that our method calls. The id used for storing the autoderef mappings being the method call itself rather than the receiver argument it will cause an ICE when we are type checking all arguments for the case of: Foo(a, bar.baz(123)) This ensures we store the autoderef mappings directly on the reciever instead. --- gcc/rust/backend/rust-compile-expr.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 35861c1..8576cf2 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1035,9 +1035,11 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) } // lookup the autoderef mappings + HirId autoderef_mappings_id + = expr.get_receiver ()->get_mappings ().get_hirid (); std::vector *adjustments = nullptr; - ok = ctx->get_tyctx ()->lookup_autoderef_mappings ( - expr.get_mappings ().get_hirid (), &adjustments); + ok = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id, + &adjustments); rust_assert (ok); // apply adjustments for the fn call -- cgit v1.1 From 5d17a8b6b2c086d4df516de06ddacdf88728f6ba Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 3 Aug 2022 13:14:54 +0100 Subject: Support Autoderef coercions This is an incremental approach to get our coercion sites more acurate to rustc. This allows us to support coercions which require a deref by sharing the code from the autoderef cycle. The eventual goal here will allow us to remove the rust-tyty-coercion rules which is messy and cannot handle logic such as DST's very well. Fixes #1198 --- gcc/rust/backend/rust-compile-base.h | 5 ++++- gcc/rust/backend/rust-compile-expr.cc | 13 +++++++------ gcc/rust/backend/rust-compile-expr.h | 14 ++++++++------ gcc/rust/backend/rust-compile-stmt.h | 3 ++- gcc/rust/backend/rust-compile.cc | 28 +++++++++++++++++++++++----- 5 files changed, 44 insertions(+), 19 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index aad0da3..5a0ac8f 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -40,9 +40,12 @@ protected: protected: Context *get_context () { return ctx; } - tree coercion_site (tree rvalue, const TyTy::BaseType *actual, + tree coercion_site (HirId id, tree rvalue, const TyTy::BaseType *actual, const TyTy::BaseType *expected, Location lvalue_locus, Location rvalue_locus); + tree coercion_site1 (tree rvalue, const TyTy::BaseType *actual, + const TyTy::BaseType *expected, Location lvalue_locus, + Location rvalue_locus); tree coerce_to_dyn_object (tree compiled_ref, const TyTy::BaseType *actual, const TyTy::BaseType *expected, diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 8576cf2..38d10d2 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -853,8 +853,9 @@ CompileExpr::visit (HIR::CallExpr &expr) Location lvalue_locus = ctx->get_mappings ()->lookup_location (expected->get_ty_ref ()); Location rvalue_locus = argument->get_locus (); - rvalue = coercion_site (rvalue, actual, expected, lvalue_locus, - rvalue_locus); + rvalue + = coercion_site (argument->get_mappings ().get_hirid (), rvalue, + actual, expected, lvalue_locus, rvalue_locus); // add it to the list arguments.push_back (rvalue); @@ -951,8 +952,8 @@ CompileExpr::visit (HIR::CallExpr &expr) Location lvalue_locus = ctx->get_mappings ()->lookup_location (expected->get_ty_ref ()); Location rvalue_locus = argument->get_locus (); - rvalue - = coercion_site (rvalue, actual, expected, lvalue_locus, rvalue_locus); + rvalue = coercion_site (argument->get_mappings ().get_hirid (), rvalue, + actual, expected, lvalue_locus, rvalue_locus); // add it to the list args.push_back (rvalue); @@ -1069,8 +1070,8 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) Location lvalue_locus = ctx->get_mappings ()->lookup_location (expected->get_ty_ref ()); Location rvalue_locus = argument->get_locus (); - rvalue - = coercion_site (rvalue, actual, expected, lvalue_locus, rvalue_locus); + rvalue = coercion_site (argument->get_mappings ().get_hirid (), rvalue, + actual, expected, lvalue_locus, rvalue_locus); // add it to the list args.push_back (rvalue); diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index bc14239..9b8976d 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -177,9 +177,9 @@ public: expr.get_rhs ()->get_mappings ().get_hirid (), &actual); rust_assert (ok); - rvalue - = coercion_site (rvalue, actual, expected, expr.get_lhs ()->get_locus (), - expr.get_rhs ()->get_locus ()); + rvalue = coercion_site (expr.get_mappings ().get_hirid (), rvalue, actual, + expected, expr.get_lhs ()->get_locus (), + expr.get_rhs ()->get_locus ()); tree assignment = ctx->get_backend ()->assignment_statement (lvalue, rvalue, @@ -435,8 +435,9 @@ public: if (ok) { - rvalue = coercion_site (rvalue, actual, expected, lvalue_locus, - rvalue_locus); + rvalue + = coercion_site (argument->get_mappings ().get_hirid (), rvalue, + actual, expected, lvalue_locus, rvalue_locus); } // add it to the list @@ -469,7 +470,8 @@ public: // compile/torture/struct_base_init_1.rs if (ok) { - rvalue = coercion_site (rvalue, actual, expected, lvalue_locus, + rvalue = coercion_site (argument->get_mappings ().get_hirid (), + rvalue, actual, expected, lvalue_locus, rvalue_locus); } diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h index aa17a4a..9bb4b7b 100644 --- a/gcc/rust/backend/rust-compile-stmt.h +++ b/gcc/rust/backend/rust-compile-stmt.h @@ -87,7 +87,8 @@ public: Location lvalue_locus = stmt.get_pattern ()->get_locus (); Location rvalue_locus = stmt.get_init_expr ()->get_locus (); TyTy::BaseType *expected = ty; - init = coercion_site (init, actual, expected, lvalue_locus, rvalue_locus); + init = coercion_site (stmt.get_mappings ().get_hirid (), init, actual, + expected, lvalue_locus, rvalue_locus); auto fnctx = ctx->peek_fn (); if (ty->is_unit ()) diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 4f17fa6..8a614f2 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -198,10 +198,26 @@ CompileStructExprField::visit (HIR::StructExprFieldIdentifier &field) // Shared methods in compilation tree -HIRCompileBase::coercion_site (tree rvalue, const TyTy::BaseType *rval, +HIRCompileBase::coercion_site (HirId id, tree rvalue, + const TyTy::BaseType *rval, const TyTy::BaseType *lval, Location lvalue_locus, Location rvalue_locus) { + std::vector *adjustments = nullptr; + bool ok = ctx->get_tyctx ()->lookup_autoderef_mappings (id, &adjustments); + if (ok) + { + rvalue = resolve_adjustements (*adjustments, rvalue, rvalue_locus); + } + + return coercion_site1 (rvalue, rval, lval, lvalue_locus, rvalue_locus); +} + +tree +HIRCompileBase::coercion_site1 (tree rvalue, const TyTy::BaseType *rval, + const TyTy::BaseType *lval, + Location lvalue_locus, Location rvalue_locus) +{ if (rvalue == error_mark_node) return error_mark_node; @@ -227,8 +243,8 @@ HIRCompileBase::coercion_site (tree rvalue, const TyTy::BaseType *rval, tree deref_rvalue = indirect_expression (rvalue, rvalue_locus); tree coerced - = coercion_site (deref_rvalue, act->get_base (), exp->get_base (), - lvalue_locus, rvalue_locus); + = coercion_site1 (deref_rvalue, act->get_base (), exp->get_base (), + lvalue_locus, rvalue_locus); if (exp->is_dyn_object () && SLICE_TYPE_P (TREE_TYPE (coerced))) return coerced; @@ -269,8 +285,10 @@ HIRCompileBase::coercion_site (tree rvalue, const TyTy::BaseType *rval, rust_assert (actual_base != nullptr); tree deref_rvalue = indirect_expression (rvalue, rvalue_locus); - tree coerced = coercion_site (deref_rvalue, actual_base, exp->get_base (), - lvalue_locus, rvalue_locus); + tree coerced + = coercion_site1 (deref_rvalue, actual_base, exp->get_base (), + lvalue_locus, rvalue_locus); + if (exp->is_dyn_object () && SLICE_TYPE_P (TREE_TYPE (coerced))) return coerced; -- cgit v1.1