c-common.c (conversion_warning): Use get_unwidened instead of get_narrower.

2007-11-26  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
	
	* c-common.c (conversion_warning): Use get_unwidened instead of
	get_narrower.

From-SVN: r130447
parent b4b56033
2007-11-26 Manuel Lopez-Ibanez <manu@gcc.gnu.org> 2007-11-26 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* c-common.c (conversion_warning): Use get_unwidened instead of
get_narrower.
2007-11-26 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c/23722 PR c/23722
* c-parser.c (struct c_parser): New bit in_if_block. * c-parser.c (struct c_parser): New bit in_if_block.
(c_parser_compound_statement_nostart): Handle unexpected 'else' (c_parser_compound_statement_nostart): Handle unexpected 'else'
...@@ -1281,12 +1281,7 @@ conversion_warning (tree type, tree expr) ...@@ -1281,12 +1281,7 @@ conversion_warning (tree type, tree expr)
&& TREE_CODE (type) == INTEGER_TYPE) && TREE_CODE (type) == INTEGER_TYPE)
{ {
/* Don't warn about unsigned char y = 0xff, x = (int) y; */ /* Don't warn about unsigned char y = 0xff, x = (int) y; */
int uns; expr = get_unwidened (expr, 0);
tree orig_expr = expr;
expr = get_narrower (expr, &uns);
if (expr == orig_expr)
uns = TYPE_UNSIGNED (TREE_TYPE (expr));
/* Warn for integer types converted to smaller integer types. */ /* Warn for integer types converted to smaller integer types. */
if (formal_prec < TYPE_PRECISION (TREE_TYPE (expr))) if (formal_prec < TYPE_PRECISION (TREE_TYPE (expr)))
...@@ -1295,32 +1290,15 @@ conversion_warning (tree type, tree expr) ...@@ -1295,32 +1290,15 @@ conversion_warning (tree type, tree expr)
/* When they are the same width but different signedness, /* When they are the same width but different signedness,
then the value may change. */ then the value may change. */
else if ((formal_prec == TYPE_PRECISION (TREE_TYPE (expr)) else if ((formal_prec == TYPE_PRECISION (TREE_TYPE (expr))
&& uns != TYPE_UNSIGNED (type)) && TYPE_UNSIGNED (TREE_TYPE (expr)) != TYPE_UNSIGNED (type))
/* Even when converted to a bigger type, if the type is /* Even when converted to a bigger type, if the type is
unsigned but expr is signed, then negative values unsigned but expr is signed, then negative values
will be changed. */ will be changed. */
|| (TYPE_UNSIGNED (type) && !uns)) || (TYPE_UNSIGNED (type) && !TYPE_UNSIGNED (TREE_TYPE (expr))))
{
if (uns != TYPE_UNSIGNED (TREE_TYPE (expr)))
{
/* For signed char s1, s2 = (int) (unsigned char) s1;
get_narrower returns s1, but uns = 1. Find the
narrowest type with uns == TYPE_UNSIGNED (type). */
tree unsexpr = orig_expr;
while (TREE_CODE (unsexpr) == NOP_EXPR
&& unsexpr != expr
&& TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (unsexpr,
0)))
== uns)
unsexpr = TREE_OPERAND (unsexpr, 0);
expr = unsexpr;
}
warning (OPT_Wsign_conversion, warning (OPT_Wsign_conversion,
"conversion to %qT from %qT may change the sign of the result", "conversion to %qT from %qT may change the sign of the result",
type, TREE_TYPE (expr)); type, TREE_TYPE (expr));
} }
}
/* Warn for integer types converted to real types if and only if /* Warn for integer types converted to real types if and only if
all the range of values of the integer type cannot be all the range of values of the integer type cannot be
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment