diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-03-04 15:14:12 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-03-07 12:16:18 +0000 |
commit | 7820ff8b8b14e1309aade205e50ef30bb08cb3e5 (patch) | |
tree | 33ca33f20795707b58b694fab16039d0c2c7374a /gcc/rust/backend/rust-compile-resolve-path.cc | |
parent | e00311aa9aabf447f27031cc5ffc114c5fbd8551 (diff) | |
download | gcc-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-resolve-path.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-resolve-path.cc | 22 |
1 files changed, 18 insertions, 4 deletions
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 |