http://gcc.gnu.org/ml/gcc-patches/2012-04/msg00191.html
and discussed in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52283 I would like to close the associated PRs to fix a few discrepancies with the folding of constant expressions warnings. Original patch from Manu was slightly modified to reflect the new warn_if_unused_value location (moved from stmt.c to c-familly/c-common.c). Is it OK for trunk, bootstrapped and regtested on x86 Many Thanks Christian
gcc/testsuite/ChangeLog 2010-02-15 Christian Bruel <christian.br...@st.com> * gcc.dg/case-const-1.c: Test constant expression. * gcc.dg/case-const-2.c: Likewise. * gcc.dg/case-const-3.c: Likewise. gcc/ChangeLog 2012-03-29 Manuel López-Ibáñez <m...@gcc.gnu.org> PR c/52283 * c-familly/c-common.c (warn_if_unused_value): Skip NOP_EXPR. * convert.c (convert_to_integer): Don't set TREE_NO_WARNING. Index: gcc/c-family/c-common.c =================================================================== --- gcc/c-family/c-common.c (revision 186524) +++ gcc/c-family/c-common.c (working copy) @@ -1692,6 +1692,7 @@ case SAVE_EXPR: case NON_LVALUE_EXPR: + case NOP_EXPR: exp = TREE_OPERAND (exp, 0); goto restart; Index: gcc/convert.c =================================================================== --- gcc/convert.c (revision 186524) +++ gcc/convert.c (working copy) @@ -537,7 +537,6 @@ else if (outprec >= inprec) { enum tree_code code; - tree tem; /* If the precision of the EXPR's type is K bits and the destination mode has more bits, and the sign is changing, @@ -555,13 +554,7 @@ else code = NOP_EXPR; - tem = fold_unary (code, type, expr); - if (tem) - return tem; - - tem = build1 (code, type, expr); - TREE_NO_WARNING (tem) = 1; - return tem; + return fold_build1 (code, type, expr); } /* If TYPE is an enumeral type or a type with a precision less Index: gcc/testsuite/gcc.dg/pr37985.c =================================================================== --- gcc/testsuite/gcc.dg/pr37985.c (revision 0) +++ gcc/testsuite/gcc.dg/pr37985.c (revision 0) @@ -0,0 +1,8 @@ +/* PR c37985 */ +/* { dg-do compile } */ +/* { dg-options " -Wall -Wextra " } */ +unsigned char foo(unsigned char a) +{ + a >> 2; /* { dg-warning "no effect" } */ + return a; +} Index: gcc/testsuite/gcc.dg/case-const-1.c =================================================================== --- gcc/testsuite/gcc.dg/case-const-1.c (revision 186524) +++ gcc/testsuite/gcc.dg/case-const-1.c (working copy) @@ -1,9 +1,11 @@ /* Test for case labels not integer constant expressions but folding - to integer constants (used in Linux kernel, PR 39613). */ + to integer constants (used in Linux kernel, PR 39613, 52283). */ /* { dg-do compile } */ /* { dg-options "" } */ extern int i; +extern unsigned int u; + void f (int c) { @@ -13,3 +15,13 @@ ; } } + +void +b (int c) +{ + switch (c) + { + case (int) (2 | ((4 < 8) ? 8 : u)): + ; + } +} Index: gcc/testsuite/gcc.dg/case-const-2.c =================================================================== --- gcc/testsuite/gcc.dg/case-const-2.c (revision 186524) +++ gcc/testsuite/gcc.dg/case-const-2.c (working copy) @@ -1,9 +1,11 @@ /* Test for case labels not integer constant expressions but folding - to integer constants (used in Linux kernel, PR 39613). */ + to integer constants (used in Linux kernel, PR 39613, 52283). */ /* { dg-do compile } */ /* { dg-options "-pedantic" } */ extern int i; +extern unsigned int u; + void f (int c) { @@ -13,3 +15,14 @@ ; } } + +void +b (int c) +{ + switch (c) + { + case (int) (2 | ((4 < 8) ? 8 : u)): /* { dg-warning "case label is not an integer constant expression" } */ + ; + } +} + Index: gcc/testsuite/gcc.dg/case-const-3.c =================================================================== --- gcc/testsuite/gcc.dg/case-const-3.c (revision 186524) +++ gcc/testsuite/gcc.dg/case-const-3.c (working copy) @@ -1,9 +1,11 @@ /* Test for case labels not integer constant expressions but folding - to integer constants (used in Linux kernel, PR 39613). */ + to integer constants (used in Linux kernel, PR 39613, 52283, ). */ /* { dg-do compile } */ /* { dg-options "-pedantic-errors" } */ extern int i; +extern unsigned int u; + void f (int c) { @@ -13,3 +15,16 @@ ; } } + +void +b (int c) +{ + switch (c) + { + case (int) (2 | ((4 < 8) ? 8 : u)): /* { dg-error "case label is not an integer constant expression" } */ + ; + } +} + + +