aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-06 18:24:42 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-07 18:21:53 +0000
commit0ccc245a06e434df2c98d7f9d6036c03e4038842 (patch)
treecf06b88b66d1bd2a54cc1db7e10ea40fc4c09deb /gcc/rust/backend/rust-compile-expr.h
parentdb7134353447921136a321b8fd78cea78f2c344e (diff)
downloadgcc-0ccc245a06e434df2c98d7f9d6036c03e4038842.zip
gcc-0ccc245a06e434df2c98d7f9d6036c03e4038842.tar.gz
gcc-0ccc245a06e434df2c98d7f9d6036c03e4038842.tar.bz2
With the merge of BlockExprs
Further testing found regressions with implicit returns and type resolution. This unifies the type resolution in block expressions to be more strict and ensure everything bar the final statement should be UnitType.
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h31
1 files changed, 20 insertions, 11 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index b823d29..686fb7f 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -460,22 +460,31 @@ public:
return;
}
- fncontext fnctx = ctx->peek_fn ();
- Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
- Btype *block_type = TyTyResolveCompile::compile (ctx, block_tyty);
-
- bool is_address_taken = false;
- Bstatement *ret_var_stmt = nullptr;
- Bvariable *tmp = ctx->get_backend ()->temporary_variable (
- fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
- expr.get_locus (), &ret_var_stmt);
- ctx->add_statement (ret_var_stmt);
+ Bvariable *tmp = NULL;
+ bool needs_temp = block_tyty->get_kind () != TyTy::TypeKind::UNIT;
+ if (needs_temp)
+ {
+ fncontext fnctx = ctx->peek_fn ();
+ Bblock *enclosing_scope = ctx->peek_enclosing_scope ();
+ Btype *block_type = TyTyResolveCompile::compile (ctx, block_tyty);
+
+ bool is_address_taken = false;
+ Bstatement *ret_var_stmt = nullptr;
+ tmp = ctx->get_backend ()->temporary_variable (
+ fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken,
+ expr.get_locus (), &ret_var_stmt);
+ ctx->add_statement (ret_var_stmt);
+ }
auto code_block = CompileBlock::compile (&expr, ctx, tmp);
auto block_stmt = ctx->get_backend ()->block_statement (code_block);
ctx->add_statement (block_stmt);
- translated = ctx->get_backend ()->var_expression (tmp, expr.get_locus ());
+ if (tmp != NULL)
+ {
+ translated
+ = ctx->get_backend ()->var_expression (tmp, expr.get_locus ());
+ }
}
void visit (HIR::StructExprStructFields &struct_expr)