Commit b9861bff by Richard Henderson Committed by Richard Henderson

stmt.c (warn_if_unused_value): Add locus argument.

        * stmt.c (warn_if_unused_value): Add locus argument.
        * tree.h (warn_if_unused_value): Update decl.
        * c-typeck.c (internal_build_compound_expr): Update call.
        * c-gimplify.c (gimplify_expr_stmt): Likewise.

From-SVN: r83416
parent 91278841
2004-06-20 Richard Henderson <rth@redhat.com>
* stmt.c (warn_if_unused_value): Add locus argument.
* tree.h (warn_if_unused_value): Update decl.
* c-typeck.c (internal_build_compound_expr): Update call.
* c-gimplify.c (gimplify_expr_stmt): Likewise.
2004-06-20 Andrew Pinski <pinskia@physics.uc.edu> 2004-06-20 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/16089 PR middle-end/16089
......
...@@ -239,12 +239,7 @@ gimplify_expr_stmt (tree *stmt_p) ...@@ -239,12 +239,7 @@ gimplify_expr_stmt (tree *stmt_p)
warning ("statement with no effect"); warning ("statement with no effect");
} }
else if (warn_unused_value) else if (warn_unused_value)
{ warn_if_unused_value (stmt, input_location);
/* Kludge for 20020220-2.c. warn_if_unused_value shouldn't use
the stmt file location info. */
set_file_and_line_for_stmt (input_location);
warn_if_unused_value (stmt);
}
} }
if (stmt == NULL_TREE) if (stmt == NULL_TREE)
......
...@@ -2949,7 +2949,7 @@ internal_build_compound_expr (tree list, int first_p) ...@@ -2949,7 +2949,7 @@ internal_build_compound_expr (tree list, int first_p)
`foo() + bar(), baz()' the result of the `+' operator is not used, `foo() + bar(), baz()' the result of the `+' operator is not used,
so we should issue a warning. */ so we should issue a warning. */
else if (warn_unused_value) else if (warn_unused_value)
warn_if_unused_value (TREE_VALUE (list)); warn_if_unused_value (TREE_VALUE (list), input_location);
return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest); return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
} }
......
...@@ -2097,7 +2097,7 @@ expand_expr_stmt_value (tree exp, int want_value, int maybe_last) ...@@ -2097,7 +2097,7 @@ expand_expr_stmt_value (tree exp, int want_value, int maybe_last)
&& warn_unused_value) && warn_unused_value)
{ {
if (TREE_SIDE_EFFECTS (exp)) if (TREE_SIDE_EFFECTS (exp))
warn_if_unused_value (exp); warn_if_unused_value (exp, emit_locus);
else if (!VOID_TYPE_P (TREE_TYPE (exp)) && !TREE_NO_WARNING (exp)) else if (!VOID_TYPE_P (TREE_TYPE (exp)) && !TREE_NO_WARNING (exp))
warning ("%Hstatement with no effect", &emit_locus); warning ("%Hstatement with no effect", &emit_locus);
} }
...@@ -2155,11 +2155,13 @@ expand_expr_stmt_value (tree exp, int want_value, int maybe_last) ...@@ -2155,11 +2155,13 @@ expand_expr_stmt_value (tree exp, int want_value, int maybe_last)
} }
/* Warn if EXP contains any computations whose results are not used. /* Warn if EXP contains any computations whose results are not used.
Return 1 if a warning is printed; 0 otherwise. */ Return 1 if a warning is printed; 0 otherwise. LOCUS is the
(potential) location of the expression. */
int int
warn_if_unused_value (tree exp) warn_if_unused_value (tree exp, location_t locus)
{ {
restart:
if (TREE_USED (exp)) if (TREE_USED (exp))
return 0; return 0;
...@@ -2169,6 +2171,9 @@ warn_if_unused_value (tree exp) ...@@ -2169,6 +2171,9 @@ warn_if_unused_value (tree exp)
if (VOID_TYPE_P (TREE_TYPE (exp))) if (VOID_TYPE_P (TREE_TYPE (exp)))
return 0; return 0;
if (EXPR_LOCUS (exp))
locus = *EXPR_LOCUS (exp);
switch (TREE_CODE (exp)) switch (TREE_CODE (exp))
{ {
case PREINCREMENT_EXPR: case PREINCREMENT_EXPR:
...@@ -2187,25 +2192,29 @@ warn_if_unused_value (tree exp) ...@@ -2187,25 +2192,29 @@ warn_if_unused_value (tree exp)
case BIND_EXPR: case BIND_EXPR:
/* For a binding, warn if no side effect within it. */ /* For a binding, warn if no side effect within it. */
return warn_if_unused_value (TREE_OPERAND (exp, 1)); exp = BIND_EXPR_BODY (exp);
goto restart;
case SAVE_EXPR: case SAVE_EXPR:
return warn_if_unused_value (TREE_OPERAND (exp, 0)); exp = TREE_OPERAND (exp, 0);
goto restart;
case TRUTH_ORIF_EXPR: case TRUTH_ORIF_EXPR:
case TRUTH_ANDIF_EXPR: case TRUTH_ANDIF_EXPR:
/* In && or ||, warn if 2nd operand has no side effect. */ /* In && or ||, warn if 2nd operand has no side effect. */
return warn_if_unused_value (TREE_OPERAND (exp, 1)); exp = TREE_OPERAND (exp, 1);
goto restart;
case COMPOUND_EXPR: case COMPOUND_EXPR:
if (TREE_NO_WARNING (exp)) if (TREE_NO_WARNING (exp))
return 0; return 0;
if (warn_if_unused_value (TREE_OPERAND (exp, 0))) if (warn_if_unused_value (TREE_OPERAND (exp, 0), locus))
return 1; return 1;
/* Let people do `(foo (), 0)' without a warning. */ /* Let people do `(foo (), 0)' without a warning. */
if (TREE_CONSTANT (TREE_OPERAND (exp, 1))) if (TREE_CONSTANT (TREE_OPERAND (exp, 1)))
return 0; return 0;
return warn_if_unused_value (TREE_OPERAND (exp, 1)); exp = TREE_OPERAND (exp, 1);
goto restart;
case NOP_EXPR: case NOP_EXPR:
case CONVERT_EXPR: case CONVERT_EXPR:
...@@ -2233,7 +2242,10 @@ warn_if_unused_value (tree exp) ...@@ -2233,7 +2242,10 @@ warn_if_unused_value (tree exp)
/* Don't warn about automatic dereferencing of references, since /* Don't warn about automatic dereferencing of references, since
the user cannot control it. */ the user cannot control it. */
if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE) if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE)
return warn_if_unused_value (TREE_OPERAND (exp, 0)); {
exp = TREE_OPERAND (exp, 0);
goto restart;
}
/* Fall through. */ /* Fall through. */
default: default:
...@@ -2255,7 +2267,7 @@ warn_if_unused_value (tree exp) ...@@ -2255,7 +2267,7 @@ warn_if_unused_value (tree exp)
if (TREE_SIDE_EFFECTS (exp)) if (TREE_SIDE_EFFECTS (exp))
return 0; return 0;
warning ("%Hvalue computed is not used", &emit_locus); warning ("%Hvalue computed is not used", &locus);
return 1; return 1;
} }
} }
......
...@@ -3240,7 +3240,7 @@ extern tree expand_start_stmt_expr (int); ...@@ -3240,7 +3240,7 @@ extern tree expand_start_stmt_expr (int);
extern tree expand_end_stmt_expr (tree); extern tree expand_end_stmt_expr (tree);
extern void expand_expr_stmt (tree); extern void expand_expr_stmt (tree);
extern void expand_expr_stmt_value (tree, int, int); extern void expand_expr_stmt_value (tree, int, int);
extern int warn_if_unused_value (tree); extern int warn_if_unused_value (tree, location_t);
extern void expand_decl_init (tree); extern void expand_decl_init (tree);
extern void clear_last_expr (void); extern void clear_last_expr (void);
extern void expand_label (tree); extern void expand_label (tree);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment