diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-10-05 14:50:29 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-10-05 15:09:09 +0100 |
commit | f6a04f38d51f6ca4319219f101e3f58660b128dc (patch) | |
tree | 755b5bebd0b063be0464510d00bef0886a9aa03c /gcc/rust/backend/rust-compile-expr.h | |
parent | 591b43e42e7f63841ce46fdd4f2760e47b6a7b0d (diff) | |
download | gcc-f6a04f38d51f6ca4319219f101e3f58660b128dc.zip gcc-f6a04f38d51f6ca4319219f101e3f58660b128dc.tar.gz gcc-f6a04f38d51f6ca4319219f101e3f58660b128dc.tar.bz2 |
Ensure we emit the code for coercion sites on CallExpr and MethodCallExpr
When we coerce the types of arguments to the parameters of functions for
example we must store the actual type of the argument at that HIR ID not
the coerced ones. This gives the backend a chance to then figure out
when to actually implement any coercion site code. such as computing the
dynamic objects.
Fixes: #700
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index eb245dc..b1a0f07 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -363,12 +363,28 @@ public: void visit (HIR::AssignmentExpr &expr) override { fncontext fn = ctx->peek_fn (); - auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx); - auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx); + auto lvalue = CompileExpr::Compile (expr.get_lhs (), ctx); + auto rvalue = CompileExpr::Compile (expr.get_rhs (), ctx); + + // assignments are coercion sites so lets convert the rvalue if necessary + TyTy::BaseType *expected = nullptr; + TyTy::BaseType *actual = nullptr; + + bool ok; + ok = ctx->get_tyctx ()->lookup_type ( + expr.get_lhs ()->get_mappings ().get_hirid (), &expected); + rust_assert (ok); + + ok = ctx->get_tyctx ()->lookup_type ( + expr.get_rhs ()->get_mappings ().get_hirid (), &actual); + rust_assert (ok); + + rvalue = coercion_site (rvalue, actual, expected, expr.get_locus ()); Bstatement *assignment - = ctx->get_backend ()->assignment_statement (fn.fndecl, lhs, rhs, + = ctx->get_backend ()->assignment_statement (fn.fndecl, lvalue, rvalue, expr.get_locus ()); + ctx->add_statement (assignment); } |