aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.cc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-03-04 15:14:12 +0000
committerPhilip Herron <philip.herron@embecosm.com>2022-03-07 12:16:18 +0000
commit7820ff8b8b14e1309aade205e50ef30bb08cb3e5 (patch)
tree33ca33f20795707b58b694fab16039d0c2c7374a /gcc/rust/backend/rust-compile-expr.cc
parente00311aa9aabf447f27031cc5ffc114c5fbd8551 (diff)
downloadgcc-7820ff8b8b14e1309aade205e50ef30bb08cb3e5.zip
gcc-7820ff8b8b14e1309aade205e50ef30bb08cb3e5.tar.gz
gcc-7820ff8b8b14e1309aade205e50ef30bb08cb3e5.tar.bz2
Remove old unused code pass this was too generic
This now uses the TREE_USED fields on GCC tree's to track the usage of VAR_DECLS, PARM_DECLS and CONST_DECLS. The code does a pass over the body and parameters of functions as a lint pass. Fixes #676
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc9
1 files changed, 9 insertions, 0 deletions
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;
+ }
}
}