aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-item.h
diff options
context:
space:
mode:
authorSimplyTheOther <simplytheother@gmail.com>2021-01-10 14:30:39 +0800
committerSimplyTheOther <simplytheother@gmail.com>2021-01-10 14:30:39 +0800
commitb247c0d5aadf6eb7323641ffbcf7cc67bedd2c52 (patch)
tree3a4d3a0b0569d28f679ecbc74928125034d50f4f /gcc/rust/backend/rust-compile-item.h
parentee85db852a5a819e559ab00e7a382a34e925447a (diff)
parent0f42a240e53e932de0ae4799d54fe0bd15d06047 (diff)
downloadgcc-b247c0d5aadf6eb7323641ffbcf7cc67bedd2c52.zip
gcc-b247c0d5aadf6eb7323641ffbcf7cc67bedd2c52.tar.gz
gcc-b247c0d5aadf6eb7323641ffbcf7cc67bedd2c52.tar.bz2
Merge branch 'master' of https://github.com/redbrain/gccrs
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.h')
-rw-r--r--gcc/rust/backend/rust-compile-item.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index 90630bb..f1b39da 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -232,6 +232,23 @@ public:
return true;
});
+ if (function_body->has_expr ())
+ {
+ // the previous passes will ensure this is a valid return
+ // dead code elimination should remove any bad trailing expressions
+ Bexpression *compiled_expr
+ = CompileExpr::Compile (function_body->expr.get (), ctx);
+ rust_assert (compiled_expr != nullptr);
+
+ auto fncontext = ctx->peek_fn ();
+
+ std::vector<Bexpression *> retstmts;
+ retstmts.push_back (compiled_expr);
+ auto s = ctx->get_backend ()->return_statement (
+ fncontext.fndecl, retstmts, function_body->expr->get_locus_slow ());
+ ctx->add_statement (s);
+ }
+
ctx->pop_block ();
auto body = ctx->get_backend ()->block_statement (code_block);
if (!ctx->get_backend ()->function_set_body (fndecl, body))