This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C PATCH for c/64637 (better location for -Wunused-value)
- From: David Malcolm <dmalcolm at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Wed, 16 Dec 2015 10:04:05 -0500
- Subject: Re: C PATCH for c/64637 (better location for -Wunused-value)
- Authentication-results: sourceware.org; auth=none
- References: <20151216145831 dot GF3296 at redhat dot com>
On Wed, 2015-12-16 at 15:58 +0100, Marek Polacek wrote:
> The following improves the location for "statement with no effect" warning by
> using the location of the expression if available. Can't use EXPR_LOCATION as
> *_DECLs still don't carry a location.
Out of interest, does it emit sane underlined ranges for these cases,
with the patch?
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2015-12-16 Marek Polacek <polacek@redhat.com>
>
> PR c/64637
> * c-typeck.c (c_process_expr_stmt): Use location of the expression if
> available.
>
> * gcc.dg/pr64637.c: New test.
>
> diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
> index 9d6c604..a147ac6 100644
> --- gcc/c/c-typeck.c
> +++ gcc/c/c-typeck.c
> @@ -10131,7 +10131,7 @@ c_process_expr_stmt (location_t loc, tree expr)
> out which is the result. */
> if (!STATEMENT_LIST_STMT_EXPR (cur_stmt_list)
> && warn_unused_value)
> - emit_side_effect_warnings (loc, expr);
> + emit_side_effect_warnings (EXPR_LOC_OR_LOC (expr, loc), expr);
>
> exprv = expr;
> while (TREE_CODE (exprv) == COMPOUND_EXPR)
> diff --git gcc/testsuite/gcc.dg/pr64637.c gcc/testsuite/gcc.dg/pr64637.c
> index e69de29..779ff50 100644
> --- gcc/testsuite/gcc.dg/pr64637.c
> +++ gcc/testsuite/gcc.dg/pr64637.c
> @@ -0,0 +1,25 @@
> +/* PR c/64637 */
> +/* { dg-do compile } */
> +/* { dg-options "-Wunused" } */
> +
> +void g ();
> +
> +void
> +f (int b)
> +{
> + for (int i = 0; i < b; i + b) /* { dg-warning "28:statement with no effect" } */
> + g ();
> + // PARM_DECLs still don't have a location, don't expect an exact location.
> + for (int i = 0; i < b; b) /* { dg-warning "statement with no effect" } */
> + g ();
> + for (int i = 0; i < b; !i) /* { dg-warning "26:statement with no effect" } */
> + g ();
> + for (!b;;) /* { dg-warning "8:statement with no effect" } */
> + g ();
> + for (;; b * 2) /* { dg-warning "13:statement with no effect" } */
> + g ();
> + ({
> + b / 5; /* { dg-warning "8:statement with no effect" } */
> + b ^ 5;
> + });
> +}
>
> Marek