Fix #52283 error: case label does not reduce to an integer constant

From-SVN: r186586
This commit is contained in:
Christian Bruel 2012-04-19 11:06:53 +02:00
parent daa573866d
commit 007a787db4
6 changed files with 40 additions and 8 deletions

View File

@ -1,3 +1,9 @@
2012-04-19 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/52283/37985
* stmt.c (warn_if_unused_value): Skip NOP_EXPR.
* convert.c (convert_to_integer): Don't set TREE_NO_WARNING.
2012-04-19 Richard Guenther <rguenther@suse.de>
PR rtl-optimization/44688

View File

@ -1692,6 +1692,7 @@ warn_if_unused_value (const_tree exp, location_t locus)
case SAVE_EXPR:
case NON_LVALUE_EXPR:
case NOP_EXPR:
exp = TREE_OPERAND (exp, 0);
goto restart;

View File

@ -537,7 +537,6 @@ convert_to_integer (tree type, tree expr)
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 @@ convert_to_integer (tree type, tree expr)
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

View File

@ -1,3 +1,11 @@
2012-04-19 Christian Bruel <christian.bruel@st.com>
* gcc.dg/pr52283.c: New test.
2012-04-19 Manuel López-Ibáñez <manu@gcc.gnu.org>
* gcc.dg/pr37985.c: New test.
2012-04-19 Richard Guenther <rguenther@suse.de>
PR rtl-optimization/44688

View File

@ -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;
}

View File

@ -0,0 +1,16 @@
/* Test for case labels not integer constant expressions but folding
to integer constants (used in Linux kernel). */
/* { dg-do compile } */
extern unsigned int u;
void
b (int c)
{
switch (c)
{
case (int) (2 | ((4 < 8) ? 8 : u)):
;
}
}