aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile.cc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-01-13 21:04:57 +0000
committerPhilip Herron <philip.herron@embecosm.com>2022-01-14 12:32:49 +0000
commit93554f3bce5bd42d8671559a774818767979cdae (patch)
tree03b1cac2b3442af423cd565b0168682e6d4541b3 /gcc/rust/backend/rust-compile.cc
parente9ffd4308d70da55b4c698b07b484063bcda0b01 (diff)
downloadgcc-93554f3bce5bd42d8671559a774818767979cdae.zip
gcc-93554f3bce5bd42d8671559a774818767979cdae.tar.gz
gcc-93554f3bce5bd42d8671559a774818767979cdae.tar.bz2
Add initial constant evaluation to blocks
BlockExpressions are usually evaluated by create a temporary variable to hold the result of the tail expression in the correctly. Const expressions do not have a context of a block so we must fold the value to store it correctly without the need for temporary variables or a stack. To do this we can leverage the fact that our constexpr code can fold simple CallExpr's so in this patch we actually generate an implicit artifical function for the block but do not add it to the translation unit and we then generate an artifical CallExpr and pass it to the constant folder system, and then assign the ConstDecl to this folded value thus reusing all of our existing BlockExpression code instead of a seperate system. Fixes #799
Diffstat (limited to 'gcc/rust/backend/rust-compile.cc')
-rw-r--r--gcc/rust/backend/rust-compile.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index b12860d..7208ed0 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -207,11 +207,11 @@ CompileStructExprField::visit (HIR::StructExprFieldIdentifier &field)
// Shared methods in compilation
void
-HIRCompileBase::compile_function_body (
- tree fndecl, std::unique_ptr<HIR::BlockExpr> &function_body,
- bool has_return_type)
+HIRCompileBase::compile_function_body (tree fndecl,
+ HIR::BlockExpr &function_body,
+ bool has_return_type)
{
- for (auto &s : function_body->get_statements ())
+ for (auto &s : function_body.get_statements ())
{
auto compiled_expr = CompileStmt::Compile (s.get (), ctx);
if (compiled_expr != nullptr)
@@ -222,12 +222,12 @@ HIRCompileBase::compile_function_body (
}
}
- if (function_body->has_expr ())
+ if (function_body.has_expr ())
{
// the previous passes will ensure this is a valid return
// or a valid trailing expression
tree compiled_expr
- = CompileExpr::Compile (function_body->expr.get (), ctx);
+ = CompileExpr::Compile (function_body.expr.get (), ctx);
if (compiled_expr != nullptr)
{
@@ -238,7 +238,7 @@ HIRCompileBase::compile_function_body (
auto ret = ctx->get_backend ()->return_statement (
fndecl, retstmts,
- function_body->get_final_expr ()->get_locus ());
+ function_body.get_final_expr ()->get_locus ());
ctx->add_statement (ret);
}
else