This fixes PR37985 where since 
http://gcc.gnu.org/ml/gcc-patches/2006-08/msg01041.html we
mark conversions produced by convert_to_integer with TREE_NO_WARNING.
This may shadow "real" stmts with no effects, thus we should
simply strip them again before checking for TREE_SIDE_EFFECTS.

Bootstrap & regtest pending on x86_64-unknown-linux-gnu.

Ok if that passes?

Thanks,
Richard.

2012-01-13  Richard Guenther  <rguent...@suse.de>

        PR c/37985
        * c-typeck.c (emit_side_effect_warnings): Strip conversions
        with TREE_NO_WARNING.

        * gcc.dg/Wunused-value-4.c: New testcase.

Index: gcc/c-typeck.c
===================================================================
*** gcc/c-typeck.c      (revision 183121)
--- gcc/c-typeck.c      (working copy)
*************** c_finish_bc_stmt (location_t loc, tree *
*** 9163,9168 ****
--- 9163,9172 ----
  static void
  emit_side_effect_warnings (location_t loc, tree expr)
  {
+   /* Strip conversions marked with TREE_NO_WARNING.  */
+   while (TREE_NO_WARNING (expr) && CONVERT_EXPR_P (expr))
+     expr = TREE_OPERAND (expr, 0);
+ 
    if (expr == error_mark_node)
      ;
    else if (!TREE_SIDE_EFFECTS (expr))
Index: gcc/testsuite/gcc.dg/Wunused-value-4.c
===================================================================
*** gcc/testsuite/gcc.dg/Wunused-value-4.c      (revision 0)
--- gcc/testsuite/gcc.dg/Wunused-value-4.c      (revision 0)
***************
*** 0 ****
--- 1,9 ----
+ /* PR c/37985 */
+ /* { dg-do compile } */
+ /* { dg-options "-Wunused-value" } */
+ 
+ unsigned char foo(unsigned char a)
+ {
+   a >> 2; /* { dg-warning "statement with no effect" } */
+   return a;
+ }

Reply via email to