aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-context.h5
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc9
-rw-r--r--gcc/rust/backend/rust-compile-item.cc4
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc22
-rw-r--r--gcc/rust/backend/rust-compile-stmt.h9
-rw-r--r--gcc/rust/backend/rust-compile-tyty.h8
6 files changed, 48 insertions, 9 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 3fefd8d..4bade5c 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -307,6 +307,11 @@ public:
return mangler.mangle_item (ty, path);
}
+ std::vector<tree> &get_type_decls () { return type_decls; }
+ std::vector<::Bvariable *> &get_var_decls () { return var_decls; }
+ std::vector<tree> &get_const_decls () { return const_decls; }
+ std::vector<tree> &get_func_decls () { return func_decls; }
+
private:
::Backend *backend;
Resolver::Resolver *resolver;
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 6d50c3f..03e3c2e 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1339,18 +1339,22 @@ CompileExpr::visit (HIR::IdentifierExpr &expr)
Bvariable *var = nullptr;
if (ctx->lookup_const_decl (ref, &translated))
{
+ TREE_USED (translated) = 1;
return;
}
else if (ctx->lookup_function_decl (ref, &fn))
{
+ TREE_USED (fn) = 1;
translated = address_expression (fn, expr.get_locus ());
}
else if (ctx->lookup_var_decl (ref, &var))
{
+ // TREE_USED is setup in the gcc abstraction here
translated = ctx->get_backend ()->var_expression (var, expr.get_locus ());
}
else if (ctx->lookup_pattern_binding (ref, &translated))
{
+ TREE_USED (translated) = 1;
return;
}
else
@@ -1371,6 +1375,11 @@ CompileExpr::visit (HIR::IdentifierExpr &expr)
else
translated = CompileItem::compile (resolved_item, ctx, lookup, true,
expr.get_locus ());
+
+ if (translated != error_mark_node)
+ {
+ TREE_USED (translated) = 1;
+ }
}
}
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index d42cc1e..21cbb1c 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -73,6 +73,10 @@ CompileItem::visit (HIR::StaticItem &var)
void
CompileItem::visit (HIR::ConstantItem &constant)
{
+ if (ctx->lookup_const_decl (constant.get_mappings ().get_hirid (),
+ &reference))
+ return;
+
// resolve the type
TyTy::BaseType *resolved_type = nullptr;
bool ok
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index e41ee7f..09f3860 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -23,6 +23,8 @@
#include "rust-hir-trait-resolve.h"
#include "rust-hir-path-probe.h"
+#include "print-tree.h"
+
namespace Rust {
namespace Compile {
@@ -117,12 +119,18 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
// might be a constant
tree constant_expr;
if (ctx->lookup_const_decl (ref, &constant_expr))
- return constant_expr;
+ {
+ TREE_USED (constant_expr) = 1;
+ return constant_expr;
+ }
// this might be a variable reference or a function reference
Bvariable *var = nullptr;
if (ctx->lookup_var_decl (ref, &var))
- return ctx->get_backend ()->var_expression (var, expr_locus);
+ {
+ // TREE_USED is setup in the gcc abstraction here
+ return ctx->get_backend ()->var_expression (var, expr_locus);
+ }
// it might be a function call
if (lookup->get_kind () == TyTy::TypeKind::FNDEF)
@@ -131,13 +139,19 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
tree fn = NULL_TREE;
if (ctx->lookup_function_decl (fntype->get_ty_ref (), &fn))
{
+ TREE_USED (fn) = 1;
return address_expression (fn, expr_locus);
}
}
// let the query system figure it out
- return query_compile (ref, lookup, final_segment, mappings, expr_locus,
- is_qualified_path);
+ tree resolved_item = query_compile (ref, lookup, final_segment, mappings,
+ expr_locus, is_qualified_path);
+ if (resolved_item != error_mark_node)
+ {
+ TREE_USED (resolved_item) = 1;
+ }
+ return resolved_item;
}
tree
diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h
index 0f69fb0..ad34253 100644
--- a/gcc/rust/backend/rust-compile-stmt.h
+++ b/gcc/rust/backend/rust-compile-stmt.h
@@ -81,6 +81,7 @@ public:
bool ok = ctx->get_tyctx ()->lookup_type (
stmt.get_init_expr ()->get_mappings ().get_hirid (), &actual);
rust_assert (ok);
+ tree stmt_type = TyTyResolveCompile::compile (ctx, ty);
Location lvalue_locus = stmt.get_pattern ()->get_locus ();
Location rvalue_locus = stmt.get_init_expr ()->get_locus ();
@@ -90,8 +91,14 @@ public:
auto fnctx = ctx->peek_fn ();
if (ty->is_unit ())
{
- // FIXME this feels wrong
ctx->add_statement (init);
+
+ auto unit_type_init_expr
+ = ctx->get_backend ()->constructor_expression (stmt_type, false, {},
+ -1, rvalue_locus);
+ auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var,
+ unit_type_init_expr);
+ ctx->add_statement (s);
}
else
{
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index a3720f8..52ad2f9 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -54,10 +54,10 @@ public:
void visit (TyTy::TupleType &type) override
{
- if (type.num_fields () == 0)
- translated = backend->unit_type ();
- else
- gcc_unreachable ();
+ // this interface is only for unit-type the -type interface takes into
+ // account the context
+ rust_assert (type.num_fields () == 0);
+ translated = backend->unit_type ();
}
void visit (TyTy::ArrayType &) override { gcc_unreachable (); }