diff options
author | Jakub Jelinek <jakub@redhat.com> | 2010-04-07 22:33:36 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2010-04-07 22:33:36 +0200 |
commit | ebfbbdc556443d1ea95923b596f59411256bd9b5 (patch) | |
tree | 2559870c4c1dbe82ba98485de0b41abd6bed7ca2 /gcc/tree.h | |
parent | 0bb8c1342ffedb0d012f007342f802e0fb692e4d (diff) | |
download | gcc-ebfbbdc556443d1ea95923b596f59411256bd9b5.zip gcc-ebfbbdc556443d1ea95923b596f59411256bd9b5.tar.gz gcc-ebfbbdc556443d1ea95923b596f59411256bd9b5.tar.bz2 |
re PR c/18624 (GCC does not detect local variable set but never used)
PR c/18624
* tree.h (DECL_READ_P): Define.
(struct tree_decl_common): Add decl_read_flag.
* c-decl.c (pop_scope): If TREE_USED but !DECL_READ_P, issue
a set but not used warning.
(merge_decls): Merge DECL_READ_P flag.
(finish_decl, build_compound_literal): Set DECL_READ_P flag.
(finish_function): Issue -Wunused-but-set-parameter diagnostics.
* c-common.c (handle_used_attribute, handle_unused_attribute):
Likewise.
* c-tree.h (default_function_array_read_conversion, mark_exp_read):
New prototypes.
* c-typeck.c (default_function_array_read_conversion, mark_exp_read):
New functions.
(default_conversion, c_process_expr_stmt): Call mark_exp_read.
* c-parser.c (c_parser_initializer, c_parser_expr_no_commas,
c_parser_binary_expression, c_parser_cast_expression,
c_parser_expr_list, c_parser_omp_atomic, c_parser_omp_for_loop):
Call default_function_array_read_conversion instead of
default_function_array_conversion where needed.
(c_parser_unary_expression, c_parser_conditional_expression,
c_parser_postfix_expression_after_primary, c_parser_initelt):
Likewise. Call mark_exp_read where needed.
(c_parser_statement_after_labels, c_parser_asm_operands,
c_parser_typeof_specifier, c_parser_sizeof_expression,
c_parser_alignof_expression, c_parser_initval): Call mark_exp_read
where needed.
* common.opt (Wunused-but-set-variable, Wunused-but-set-parameter):
New.
* toplev.c (warn_unused_but_set_variable): Default to warn_unused.
(warn_unused_but_set_parameter): Default to warn_unused
&& extra_warnings.
* doc/invoke.texi: Document -Wunused-but-set-variable and
-Wunused-but-set-parameter.
* objc-act.c (finish_var_decl, objc_begin_catch_clause,
really_start_method, get_super_receiver, handle_class_ref): Set
DECL_READ_P in addition to TREE_USED.
* gcc.dg/Wunused-var-1.c: New test.
* gcc.dg/Wunused-var-2.c: New test.
* gcc.dg/Wunused-var-3.c: New test.
* gcc.dg/Wunused-var-4.c: New test.
* gcc.dg/Wunused-var-5.c: New test.
* gcc.dg/Wunused-var-6.c: New test.
* gcc.dg/Wunused-parm-1.c: New test.
From-SVN: r158086
Diffstat (limited to 'gcc/tree.h')
-rw-r--r-- | gcc/tree.h | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -1317,6 +1317,9 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, (TREE_CHECK3 (NODE, VAR_DECL, PARM_DECL, \ RESULT_DECL)->decl_common.decl_restricted_flag) +#define DECL_READ_P(NODE) \ + (TREE_CHECK2 (NODE, VAR_DECL, PARM_DECL)->decl_common.decl_read_flag) + /* In a CALL_EXPR, means that the call is the jump from a thunk to the thunked-to function. */ #define CALL_FROM_THUNK_P(NODE) (CALL_EXPR_CHECK (NODE)->base.protected_flag) @@ -2691,8 +2694,12 @@ struct GTY(()) tree_decl_common { /* In VAR_DECL, PARM_DECL and RESULT_DECL, this is DECL_RESTRICTED_P. */ unsigned decl_restricted_flag : 1; + /* In VAR_DECL and PARM_DECL set when the decl has been used except for + being set. */ + unsigned decl_read_flag : 1; + /* Padding so that 'off_align' can be on a 32-bit boundary. */ - unsigned decl_common_unused : 2; + unsigned decl_common_unused : 1; /* DECL_OFFSET_ALIGN, used only for FIELD_DECLs. */ unsigned int off_align : 8; |