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/objc | |
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/objc')
-rw-r--r-- | gcc/objc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/objc/objc-act.c | 9 |
2 files changed, 15 insertions, 1 deletions
diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index 3063af9..4307001 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,10 @@ +2010-04-07 Jakub Jelinek <jakub@redhat.com> + + PR c/18624 + * 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. + 2010-04-07 Iain Sandoe <iains@gcc.gnu.org> PR objc/35996 diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index f5b754b..9e5fdb5 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -1,6 +1,7 @@ /* Implement classes and message passing for Objective C. Copyright (C) 1992, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. + 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 + Free Software Foundation, Inc. Contributed by Steve Naroff. This file is part of GCC. @@ -1531,6 +1532,7 @@ finish_var_decl (tree var, tree initializer) mark_decl_referenced (var); /* Mark the decl to avoid "defined but not used" warning. */ TREE_USED (var) = 1; + DECL_READ_P (var) = 1; /* We reserve the right for the runtime to use/modify these variables in ways that are opaque to us. */ DECL_PRESERVE_P (var) = 1; @@ -3867,6 +3869,7 @@ objc_begin_catch_clause (tree decl) /* ??? As opposed to __attribute__((unused))? Anyway, this appears to be what the previous objc implementation did. */ TREE_USED (decl) = 1; + DECL_READ_P (decl) = 1; /* Verify that the type of the catch is valid. It must be a pointer to an Objective-C class, or "id" (which is catch-all). */ @@ -8722,7 +8725,9 @@ really_start_method (tree method, /* Suppress unused warnings. */ TREE_USED (self_decl) = 1; + DECL_READ_P (self_decl) = 1; TREE_USED (TREE_CHAIN (self_decl)) = 1; + DECL_READ_P (TREE_CHAIN (self_decl)) = 1; #ifdef OBJCPLUS pop_lang_context (); #endif @@ -8799,6 +8804,7 @@ get_super_receiver (void) objc_super_template); /* This prevents `unused variable' warnings when compiling with -Wall. */ TREE_USED (UOBJC_SUPER_decl) = 1; + DECL_READ_P (UOBJC_SUPER_decl) = 1; lang_hooks.decls.pushdecl (UOBJC_SUPER_decl); finish_decl (UOBJC_SUPER_decl, input_location, NULL_TREE, NULL_TREE, NULL_TREE); @@ -9422,6 +9428,7 @@ handle_class_ref (tree chain) DECL_INITIAL (decl) = exp; TREE_STATIC (decl) = 1; TREE_USED (decl) = 1; + DECL_READ_P (decl) = 1; /* Force the output of the decl as this forces the reference of the class. */ mark_decl_referenced (decl); |