This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/37985] [4.4/4.5/4.6/4.7 Regression] unsigned char shift lacks "statement with no effect" warning
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 16 Jan 2012 09:00:15 +0000
- Subject: [Bug c/37985] [4.4/4.5/4.6/4.7 Regression] unsigned char shift lacks "statement with no effect" warning
- Auto-submitted: auto-generated
- References: <bug-37985-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37985
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |
--- Comment #10 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-16 09:00:15 UTC ---
The patch at http://gcc.gnu.org/ml/gcc-patches/2012-01/msg00669.html does
not work as we then warn for gcc.dg/20040202-1.c
gcc.dg/20040202-1.c:7:5: warning: statement with no effect [-Wunused-value]
which we do because we fold the memcpy (dest, src, 0); to
(dest = src, (void *)dest) with a TREE_NO_WARNING flag on the cast.
So we run afoul of having only one TREE_NO_WARNING flag, thus trying to
disable a specific warning using a cast will also disable other useful
ones.
The patch that caused this regression
(http://gcc.gnu.org/ml/gcc-patches/2006-08/msg01041.html) is patching a too
generic place to handle the situation.
That issue is probably similar to the fallout of the above patch - we fold
too much and too early for these kind of warnings (thus the C AST deviates
too much from the source input).
For the statement with no effect warning we emit that from c_process_expr_stmt
()
which calls c_fully_fold _before_ emitting those warnings (for whatever
historical reasons...). Doing
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c (revision 183205)
+++ gcc/c-typeck.c (working copy)
@@ -9186,8 +9190,6 @@ c_process_expr_stmt (location_t loc, tre
if (!expr)
return NULL_TREE;
- expr = c_fully_fold (expr, false, NULL);
-
if (warn_sequence_point)
verify_sequence_points (expr);
@@ -9213,6 +9215,8 @@ c_process_expr_stmt (location_t loc, tre
|| TREE_CODE (exprv) == ADDR_EXPR)
mark_exp_read (exprv);
+ expr = c_fully_fold (expr, false, NULL);
+
/* If the expression is not of a type to which we cannot assign a line
number, wrap the thing in a no-op NOP_EXPR. */
if (DECL_P (expr) || CONSTANT_CLASS_P (expr))
ontop of the patch "fixes" this issue.