From ba7166773bd7a4d1e0da5bad0a61c20fac3bef78 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Fri, 17 Sep 1999 22:13:07 +0000 Subject: [PATCH] tree.h (warn_about_unused_variables): Declare. * tree.h (warn_about_unused_variables): Declare. * stmt.c (warn_about_unused_variables): New function, split out from ... (expand_end_bindings): Here. From-SVN: r29486 --- gcc/ChangeLog | 7 +++++++ gcc/stmt.c | 29 ++++++++++++++++++++++------- gcc/tree.h | 1 + 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6b5daedeee0..3a9d61aeefa 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +Fri Sep 17 15:11:20 1999 Mark Mitchell + + * tree.h (warn_about_unused_variables): Declare. + * stmt.c (warn_about_unused_variables): New function, split out + from ... + (expand_end_bindings): Here. + Fri Sep 17 15:07:37 1999 Mark Mitchell * stmt.c (preserve_subexpressions_p): Don't crash when diff --git a/gcc/stmt.c b/gcc/stmt.c index 92465943f85..51110b8a78d 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -3492,6 +3492,25 @@ expand_nl_goto_receivers (thisblock) emit_label (afterward); } +/* Warn about any unused VARS (which may contain nodes other than + VAR_DECLs, but such nodes are ignored). The nodes are connected + via the TREE_CHAIN field. */ + +void +warn_about_unused_variables (vars) + tree vars; +{ + tree decl; + + if (warn_unused) + for (decl = vars; decl; decl = TREE_CHAIN (decl)) + if (TREE_CODE (decl) == VAR_DECL + && ! TREE_USED (decl) + && ! DECL_IN_SYSTEM_HEADER (decl) + && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)) + warning_with_decl (decl, "unused variable `%s'"); +} + /* Generate RTL code to terminate a binding contour. VARS is the chain of VAR_DECL nodes for the variables bound in this @@ -3532,13 +3551,9 @@ expand_end_bindings (vars, mark_ends, dont_jump_in) thisblock = block_stack; - if (warn_unused) - for (decl = vars; decl; decl = TREE_CHAIN (decl)) - if (TREE_CODE (decl) == VAR_DECL - && ! TREE_USED (decl) - && ! DECL_IN_SYSTEM_HEADER (decl) - && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)) - warning_with_decl (decl, "unused variable `%s'"); + /* If any of the variables in this scope were not used, warn the + user. */ + warn_about_unused_variables (vars); if (thisblock->exit_label) { diff --git a/gcc/tree.h b/gcc/tree.h index 669e9efbc4b..e479f99a1bb 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -2054,6 +2054,7 @@ extern void expand_return PROTO((tree)); extern int optimize_tail_recursion PROTO((tree, struct rtx_def *)); extern void expand_start_bindings PROTO((int)); extern void expand_end_bindings PROTO((tree, int, int)); +extern void warn_about_unused_variables PROTO((tree)); extern void start_cleanup_deferral PROTO((void)); extern void end_cleanup_deferral PROTO((void)); extern void mark_block_as_eh_region PROTO((void)); -- 2.30.2