Skip to content

Commit be94ef6

Browse files
committed
Change unit-type to be an empty struct so that we do not disregard the
initilizer of variables
1 parent 7a3c935 commit be94ef6

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

gcc/rust/backend/rust-compile-stmt.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class CompileStmt : public HIRCompileBase, public HIR::HIRStmtVisitor
8181
bool ok = ctx->get_tyctx ()->lookup_type (
8282
stmt.get_init_expr ()->get_mappings ().get_hirid (), &actual);
8383
rust_assert (ok);
84+
tree stmt_type = TyTyResolveCompile::compile (ctx, ty);
8485

8586
Location lvalue_locus = stmt.get_pattern ()->get_locus ();
8687
Location rvalue_locus = stmt.get_init_expr ()->get_locus ();
@@ -90,8 +91,14 @@ class CompileStmt : public HIRCompileBase, public HIR::HIRStmtVisitor
9091
auto fnctx = ctx->peek_fn ();
9192
if (ty->is_unit ())
9293
{
93-
// FIXME this feels wrong
9494
ctx->add_statement (init);
95+
96+
auto unit_type_init_expr
97+
= ctx->get_backend ()->constructor_expression (stmt_type, false, {},
98+
-1, rvalue_locus);
99+
auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var,
100+
unit_type_init_expr);
101+
ctx->add_statement (s);
95102
}
96103
else
97104
{

gcc/rust/backend/rust-compile-tyty.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class TyTyCompile : public TyTy::TyVisitor
5454

5555
void visit (TyTy::TupleType &type) override
5656
{
57-
if (type.num_fields () == 0)
58-
translated = backend->unit_type ();
59-
else
60-
gcc_unreachable ();
57+
// this interface is only for unit-type the -type interface takes into
58+
// account the context
59+
rust_assert (type.num_fields () == 0);
60+
translated = backend->unit_type ();
6161
}
6262

6363
void visit (TyTy::ArrayType &) override { gcc_unreachable (); }

gcc/rust/rust-gcc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Gcc_backend : public Backend
122122
static tree unit_type;
123123
if (unit_type == nullptr)
124124
{
125-
auto unit_type_node = integer_type (true, 0);
125+
auto unit_type_node = struct_type ({});
126126
unit_type = named_type ("()", unit_type_node,
127127
::Linemap::predeclared_location ());
128128
}

0 commit comments

Comments
 (0)