Add options -Wunused-variable, -Wunused-function, -Wunused-label,

-Wunused-parameter.  Retain existing -Wunused behavour.  Document.

From-SVN: r33953
This commit is contained in:
Andrew Cagney 2000-05-17 08:15:29 +00:00
parent ef94b7f541
commit 078721e1a2
20 changed files with 215 additions and 42 deletions

View File

@ -1,3 +1,34 @@
Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
* flags.h (warn_unused_function, warn_unused_label,
warn_unused_parameter, warn_unused_variable, warn_unused_value):
Replace ``warn_unused''.
(set_Wunused): Add declaration.
* toplev.c (set_Wunused): New function.
(warn_unused_function, warn_unused_label, warn_unused_parameter,
warn_unused_variable, warn_unused_value): New variables.
(W_options): Add -Wunused-function, -Wunused-function,
-Wunused-label, -Wunused-parameter, -Wunused-variable and
-Wunused-value. Delete -Wunused. Handled in decode_W_option.
* toplev.c (decode_W_option): Update -Wunused flags by calling
set_Wunused.
* c-decl.c (c_decode_option): Ditto for -Wall.
* stmt.c (expand_expr_stmt, expand_expr_stmt,
warn_about_unused_variables): Replace warn_unused with more
explicit warn_unused_value et.al.
* function.c (expand_function_end): Ditto.
* c-typeck.c (internal_build_compound_expr,
internal_build_compound_expr): Ditto.
* c-decl.c (poplevel, pop_label_level): Ditto.
* toplev.c (check_global_declarations): Replace warn_unused with
check for either warn_unused_function or warn_unused_variable.
* gcc.1, invoke.texi (Warning Options): Document
-Wunused-function, -Wunused-function, -Wunused-label,
-Wunused-parameter, -Wunused-variable and -Wunused-value options.
2000-05-16 Richard Henderson <rth@cygnus.com>
* config/ia64/crtbegin.asm (__dso_handle): Mark hidden if the

View File

@ -754,7 +754,7 @@ c_decode_option (argc, argv)
warn_implicit_int = 1;
mesg_implicit_function_declaration = 1;
warn_return_type = 1;
warn_unused = 1;
set_Wunused (1);
warn_switch = 1;
warn_format = 1;
warn_char_subscripts = 1;
@ -1121,7 +1121,7 @@ poplevel (keep, reverse, functionbody)
define_label (input_filename, lineno,
DECL_NAME (label));
}
else if (warn_unused && !TREE_USED (label))
else if (warn_unused_label && !TREE_USED (label))
warning_with_decl (label, "label `%s' defined but not used");
IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
@ -1282,7 +1282,7 @@ pop_label_level ()
define_label (input_filename, lineno,
DECL_NAME (TREE_VALUE (link)));
}
else if (warn_unused && !TREE_USED (TREE_VALUE (link)))
else if (warn_unused_label && !TREE_USED (TREE_VALUE (link)))
warning_with_decl (TREE_VALUE (link),
"label `%s' defined but not used");
IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;

View File

@ -3531,7 +3531,7 @@ internal_build_compound_expr (list, first_p)
/* The left-hand operand of a comma expression is like an expression
statement: with -W or -Wunused, we should warn if it doesn't have
any side-effects, unless it was explicitly cast to (void). */
if ((extra_warnings || warn_unused)
if ((extra_warnings || warn_unused_value)
&& ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
&& TREE_TYPE (TREE_VALUE (list)) == void_type_node))
warning ("left-hand operand of comma expression has no effect");
@ -3546,7 +3546,7 @@ internal_build_compound_expr (list, first_p)
side-effects, but computes a value which is not used. For example, in
`foo() + bar(), baz()' the result of the `+' operator is not used,
so we should issue a warning. */
else if (warn_unused)
else if (warn_unused_value)
warn_if_unused_value (TREE_VALUE (list));
return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);

View File

@ -1,3 +1,9 @@
Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
* decl.c (c_decode_option): Update -Wall unused flags by
calling set_Wunused.
(poplevel): Replace warn_unused with warn_unused_label.
2000-05-09 Zack Weinberg <zack@wolery.cumb.org>
* ch-tree.h: Update prototypes. Remove prototypes for

View File

@ -799,7 +799,7 @@ c_decode_option (argc, argv)
warn_uninitialized = 2;
warn_implicit = 1;
warn_return_type = 1;
warn_unused = 1;
set_Wunused (1);
warn_char_subscripts = 1;
warn_parentheses = 1;
warn_missing_braces = 1;
@ -2973,7 +2973,7 @@ poplevel (keep, reverse, functionbody)
define_label (input_filename, lineno,
DECL_NAME (label));
}
else if (warn_unused && !TREE_USED (label))
else if (warn_unused_label && !TREE_USED (label))
warning_with_decl (label, "label `%s' defined but not used");
IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;

View File

@ -1,3 +1,12 @@
Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
* decl.c (pop_label): Replace warn_unused with warn_unused_label.
* typeck.c (build_x_compound_expr): Replace warn_unused with
warn_unused_value.
* decl2.c (lang_decode_option): Update -Wall unused flags by
calling set_Wunused.
2000-05-16 Mark Mitchell <mark@codesourcery.com>
* cp-treeh (BINFO_NEW_VTABLE_MARKED): Update documentation.

View File

@ -1194,7 +1194,7 @@ pop_label (link)
/* Avoid crashing later. */
define_label (input_filename, 1, DECL_NAME (label));
}
else if (warn_unused && !TREE_USED (label))
else if (warn_unused_label && !TREE_USED (label))
cp_warning_at ("label `%D' defined but not used", label);
}

View File

@ -773,7 +773,7 @@ lang_decode_option (argc, argv)
else if (!strcmp (p, "all"))
{
warn_return_type = setting;
warn_unused = setting;
set_Wunused (setting);
warn_implicit = setting;
warn_switch = setting;
warn_format = setting;

View File

@ -5058,13 +5058,13 @@ build_x_compound_expr (list)
/* the left-hand operand of a comma expression is like an expression
statement: we should warn if it doesn't have any side-effects,
unless it was explicitly cast to (void). */
if ((extra_warnings || warn_unused)
if ((extra_warnings || warn_unused_value)
&& !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
&& TREE_TYPE (TREE_VALUE(list)) == void_type_node))
warning("left-hand operand of comma expression has no effect");
}
#if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
else if (warn_unused)
else if (warn_unused_value)
warn_if_unused_value (TREE_VALUE(list));
#endif

View File

@ -1,3 +1,8 @@
Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
* top.c (ffe_decode_option): Update -Wall unused flags by calling
set_Wunused.
2000-05-09 Zack Weinberg <zack@wolery.cumb.org>
* com.c (ffecom_subscript_check_): Constify array_name

View File

@ -510,7 +510,7 @@ ffe_decode_option (argc, argv)
warning about not using it without also specifying -O. */
if (warn_uninitialized != 1)
warn_uninitialized = 2;
warn_unused = 1;
set_Wunused (1);
}
else
return 0;

View File

@ -71,9 +71,17 @@ extern int inhibit_warnings;
extern int extra_warnings;
/* Nonzero to warn about unused local variables. */
/* Nonzero to warn about unused variables, functions et.al. Use
set_Wunused() to update the -Wunused-* flags that correspond to the
-Wunused option. */
extern int warn_unused;
extern void set_Wunused PARAMS ((int setting));
extern int warn_unused_function;
extern int warn_unused_label;
extern int warn_unused_parameter;
extern int warn_unused_variable;
extern int warn_unused_value;
/* Nonzero to warn about code which is never reached. */

View File

@ -6492,7 +6492,11 @@ expand_function_end (filename, line, end_bindings)
}
/* Warn about unused parms if extra warnings were specified. */
if (warn_unused && extra_warnings)
/* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
warning. WARN_UNUSED_PARAMETER is negative when set by
-Wunused. */
if (warn_unused_parameter > 0
|| (warn_unused_parameter < 0 && extra_warnings))
{
tree decl;

View File

@ -20,7 +20,7 @@
.if n .sp
.if t .sp 0.4
..
.Id $Id: gcc.1,v 1.13 1999/11/02 10:23:46 law Exp $
.Id $Id: gcc.1,v 1.14 2000/04/11 06:01:52 loewis Exp $
.TH GCC 1 "\*(Dt" "GNU Tools" "GNU Tools"
.SH NAME
gcc, g++ \- GNU project C and C++ Compiler (gcc-2.96)
@ -206,6 +206,11 @@ in the following sections.
\-Wtrigraphs
\-Wuninitialized
\-Wunused
\-Wunused-function
\-Wunused-label
\-Wunused-parameter
\-Wunused-variable
\-Wunused-value
\-Wwrite\-strings
.TP
.B Debugging Options
@ -1694,10 +1699,50 @@ return-value in a function whose return-type is not \c
.B void\c
\&.
.TP
.B \-Wunused\-function
Warn whenever a static function is declared but not defined or a
non\-inline static function is unused.
.TP
.B \-Wunused\-label
Warn whenever a label is declared but not used.
To suppress this warning use the
.B unused
attribute.
.TP
.B \-Wunused\-parameter
Warn whenever a function parameter is unused aside from its declaration.
To suppress this warning use the
.B unused
attribute.
.TP
.B \-Wunused\-variable
Warn whenever a local variable or non\-constant static variable
is unused aside from its declaration
To suppress this warning use the
.B unused
attribute.
.TP
.B \-Wunused\-value
Warn whenever a statement computes a result that is explicitly not used.
To suppress this warning cast the expression to
.B void\c
\&.
.TP
.B \-Wunused
Warn whenever a local variable is unused aside from its declaration,
whenever a function is declared static but never defined, and whenever
a statement computes a result that is explicitly not used.
All all the above `\|\c
.B \-Wunused\c
\&\|' options combined.
In order to get a warning about an unused function parameter, you must
either specify `\|\c
.B \-W \-Wunused\c
\&\|' or separatly specify `\|\c
.B \-Wunused\-parameter\c
\&\|'.
.TP
.B \-Wswitch
Warn whenever a \c

View File

@ -132,7 +132,8 @@ in the following sections.
-Wparentheses -Wpointer-arith -Wredundant-decls
-Wreturn-type -Wshadow -Wsign-compare -Wswitch
-Wtrigraphs -Wundef -Wuninitialized -Wunknown-pragmas -Wunreachable-code
-Wunused -Wwrite-strings
-Wunused -Wunused-function -Wunused-label -Wunused-parameter
-Wunused-variable -Wunused-value -Wwrite-strings
@end smallexample
@item C-only Warning Options
@ -1538,18 +1539,40 @@ provoke warnings when this option is used.
@item -Wtrigraphs
Warn if any trigraphs are encountered (assuming they are enabled).
@item -Wunused-function
Warn whenever a static function is declared but not defined or a
non\-inline static function is unused.
@item -Wunused-label
Warn whenever a label is declared but not used.
To suppress this warning use the @samp{unused} attribute
(@pxref{Variable Attributes}).
@item -Wunused-parameter
Warn whenever a function parameter is unused aside from its declaration.
To suppress this warning use the @samp{unused} attribute
(@pxref{Variable Attributes}).
@item -Wunused-variable
Warn whenever a local variable or non-constant static variable is unused
aside from its declaration
To suppress this warning use the @samp{unused} attribute
(@pxref{Variable Attributes}).
@item -Wunused-value
Warn whenever a statement computes a result that is explicitly not used.
To suppress this warning cast the expression to @samp{void}.
@item -Wunused
Warn whenever a variable is unused aside from its declaration,
whenever a function is declared static but never defined, whenever a
label is declared but not used, and whenever a statement computes a
result that is explicitly not used.
All all the above @samp{-Wunused} options combined.
In order to get a warning about an unused function parameter, you must
specify both @samp{-W} and @samp{-Wunused}.
To suppress this warning for an expression, simply cast it to void. For
unused variables, parameters and labels, use the @samp{unused} attribute
(@pxref{Variable Attributes}).
either specify @samp{-W -Wunused} or separatly specify
@samp{-Wunused-parameter}.
@item -Wuninitialized
Warn if an automatic variable is used without first being initialized or

View File

@ -1,4 +1,10 @@
2000-05-09 Zack Weinberg <zack@wolery.cumb.org>
Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
* lang.c (lang_decode_option): Update -Wunused flags by calling
set_Wunused.
* decl.c (poplevel): Replace warn_unused with warn_unused_label.
2000-04-19 Tom Tromey &lt;tromey@cygnus.com&gt;
* check_init.c (check_init): Constify local char *.
* class.c (push_class): Constify local char *.

View File

@ -1387,7 +1387,7 @@ poplevel (keep, reverse, functionbody)
define_label (input_filename, lineno,
DECL_NAME (label));
}
else if (warn_unused && !TREE_USED (label))
else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
warning_with_decl (label, "label `%s' defined but not used");
IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;

View File

@ -258,7 +258,7 @@ lang_decode_option (argc, argv)
flag_redundant = 1;
/* When -Wall given, enable -Wunused. We do this because the C
compiler does it, and people expect it. */
warn_unused = 1;
set_Wunused (1);
return 1;
}

View File

@ -1857,12 +1857,13 @@ expand_expr_stmt (exp)
except inside a ({...}) where they may be useful. */
if (expr_stmts_for_value == 0 && exp != error_mark_node)
{
if (! TREE_SIDE_EFFECTS (exp) && (extra_warnings || warn_unused)
if (! TREE_SIDE_EFFECTS (exp)
&& (extra_warnings || warn_unused_value)
&& !(TREE_CODE (exp) == CONVERT_EXPR
&& TREE_TYPE (exp) == void_type_node))
warning_with_file_and_line (emit_filename, emit_lineno,
"statement with no effect");
else if (warn_unused)
else if (warn_unused_value)
warn_if_unused_value (exp);
}
@ -3575,7 +3576,7 @@ warn_about_unused_variables (vars)
{
tree decl;
if (warn_unused)
if (warn_unused_variable)
for (decl = vars; decl; decl = TREE_CHAIN (decl))
if (TREE_CODE (decl) == VAR_DECL
&& ! TREE_USED (decl)

View File

@ -1289,9 +1289,30 @@ int extra_warnings = 0;
int warnings_are_errors = 0;
/* Nonzero to warn about unused local variables. */
/* Nonzero to warn about unused variables, functions et.al. */
int warn_unused;
int warn_unused_function;
int warn_unused_label;
int warn_unused_parameter;
int warn_unused_variable;
int warn_unused_value;
void
set_Wunused (setting)
int setting;
{
warn_unused_function = setting;
warn_unused_label = setting;
/* Unused function parameter warnings are reported when either ``-W
-Wunused'' or ``-Wunused-parameter'' is specified. Differentiate
-Wunused by setting WARN_UNUSED_PARAMETER to -1 */
if (!setting)
warn_unused_parameter = 0;
else if (!warn_unused_parameter)
warn_unused_parameter = -1;
warn_unused_variable = setting;
warn_unused_value = setting;
}
/* Nonzero to warn about code which is never reached. */
@ -1354,7 +1375,11 @@ int warn_padded;
lang_independent_options W_options[] =
{
{"unused", &warn_unused, 1, "Warn when a variable is unused" },
{"unused-function", &warn_unused_function, 1, "Warn when a function is unused" },
{"unused-label", &warn_unused_label, 1, "Warn when a label is unused" },
{"unused-parameter", &warn_unused_parameter, 1, "Warn when a function parameter is unused" },
{"unused-variable", &warn_unused_variable, 1, "Warn when a variable is unused" },
{"unused-value", &warn_unused_value, 1, "Warn when an expression value is unused" },
{"error", &warnings_are_errors, 1, ""},
{"shadow", &warn_shadow, 1, "Warn when one local variable shadows another" },
{"switch", &warn_switch, 1,
@ -1905,7 +1930,7 @@ check_global_declarations (vec, len)
because many programs have static variables
that exist only to get some text into the object file. */
if (TREE_CODE (decl) == FUNCTION_DECL
&& (warn_unused
&& (warn_unused_function
|| TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
&& DECL_INITIAL (decl) == 0
&& DECL_EXTERNAL (decl)
@ -1926,9 +1951,10 @@ check_global_declarations (vec, len)
/* Warn about static fns or vars defined but not used,
but not about inline functions or static consts
since defining those in header files is normal practice. */
if (warn_unused
&& ((TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
|| (TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
if (((warn_unused_function
&& TREE_CODE (decl) == FUNCTION_DECL && ! DECL_INLINE (decl))
|| (warn_unused_variable
&& TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
&& ! DECL_IN_SYSTEM_HEADER (decl)
&& ! DECL_EXTERNAL (decl)
&& ! TREE_PUBLIC (decl)
@ -3685,6 +3711,7 @@ display_help ()
W_options[i].string, description);
}
printf (" -Wunused Enable unused warnings\n");
printf (" -Wid-clash-<num> Warn if 2 identifiers have the same first <num> chars\n");
printf (" -Wlarger-than-<number> Warn if an object is larger than <number> bytes\n");
printf (" -p Enable function profiling\n");
@ -3995,6 +4022,14 @@ decode_W_option (arg)
if (larger_than_size != -1)
warn_larger_than = 1;
}
else if (!strcmp (arg, "unused"))
{
set_Wunused (1);
}
else if (!strcmp (arg, "no-unused"))
{
set_Wunused (0);
}
else
return 0;