c-common.c (c_sizeof_or_alignof_type): Use fold_convert instead of building a NOP_EXPR.

* c-common.c (c_sizeof_or_alignof_type): Use fold_convert instead
	of building a NOP_EXPR.
	(c_alignof_expr): Likewise.  Handle CONVERT_EXPR the same as
	NOP_EXPR.
	* c-convert.c (convert): Use fold_convert instead of building
	NOP_EXPRs and CONVERT_EXPRs directly.  Don't special case
	c_objc_common_truthvalue_conversion returning a NOP_EXPR.  Remove
	#if 0 code.
	* c-pretty-print.c (pp_c_cast_expression, pp_c_expression): Handle
	NOP_EXPR the same as CONVERT_EXPR.
	* c-typeck.c (build_function_call): Use fold_convert instead of
	building a NOP_EXPR directly.
	(build_compound_expr): Handle NOP_EXPR the same as CONVERT_EXPR.

testsuite:
	* gcc.dg/cast-pretty-print-1.c: New test.

From-SVN: r108001
This commit is contained in:
Joseph Myers 2005-12-03 18:58:43 +00:00 committed by Joseph Myers
parent a34a91f0b7
commit 4c7a6c1bdb
7 changed files with 45 additions and 27 deletions

View File

@ -1,3 +1,19 @@
2005-12-03 Joseph S. Myers <joseph@codesourcery.com>
* c-common.c (c_sizeof_or_alignof_type): Use fold_convert instead
of building a NOP_EXPR.
(c_alignof_expr): Likewise. Handle CONVERT_EXPR the same as
NOP_EXPR.
* c-convert.c (convert): Use fold_convert instead of building
NOP_EXPRs and CONVERT_EXPRs directly. Don't special case
c_objc_common_truthvalue_conversion returning a NOP_EXPR. Remove
#if 0 code.
* c-pretty-print.c (pp_c_cast_expression, pp_c_expression): Handle
NOP_EXPR the same as CONVERT_EXPR.
* c-typeck.c (build_function_call): Use fold_convert instead of
building a NOP_EXPR directly.
(build_compound_expr): Handle NOP_EXPR the same as CONVERT_EXPR.
2005-12-03 Alan Modra <amodra@bigpond.net.au>
PR rtl-optimization/25197

View File

@ -2873,7 +2873,7 @@ c_sizeof_or_alignof_type (tree type, bool is_sizeof, int complain)
TYPE_IS_SIZETYPE means that certain things (like overflow) will
never happen. However, this node should really have type
`size_t', which is just a typedef for an ordinary integer type. */
value = fold_build1 (NOP_EXPR, size_type_node, value);
value = fold_convert (size_type_node, value);
gcc_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)));
return value;
@ -2908,7 +2908,7 @@ c_alignof_expr (tree expr)
tree best = t;
int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
while (TREE_CODE (t) == NOP_EXPR
while ((TREE_CODE (t) == NOP_EXPR || TREE_CODE (t) == CONVERT_EXPR)
&& TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
{
int thisalign;
@ -2923,7 +2923,7 @@ c_alignof_expr (tree expr)
else
return c_alignof (TREE_TYPE (expr));
return fold_build1 (NOP_EXPR, size_type_node, t);
return fold_convert (size_type_node, t);
}
/* Handle C and C++ default attributes. */

View File

@ -88,7 +88,7 @@ convert (tree type, tree expr)
return expr;
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
return fold_build1 (NOP_EXPR, type, expr);
return fold_convert (type, expr);
if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
return error_mark_node;
if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE)
@ -97,28 +97,11 @@ convert (tree type, tree expr)
return error_mark_node;
}
if (code == VOID_TYPE)
return build1 (CONVERT_EXPR, type, e);
#if 0
/* This is incorrect. A truncation can't be stripped this way.
Extensions will be stripped by the use of get_unwidened. */
if (TREE_CODE (expr) == NOP_EXPR)
return convert (type, TREE_OPERAND (expr, 0));
#endif
return fold_convert (type, e);
if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
return fold (convert_to_integer (type, e));
if (code == BOOLEAN_TYPE)
{
tree t = c_objc_common_truthvalue_conversion (expr);
if (TREE_CODE (t) == ERROR_MARK)
return t;
/* If it returns a NOP_EXPR, we must fold it here to avoid
infinite recursion between fold () and convert (). */
if (TREE_CODE (t) == NOP_EXPR)
return fold_build1 (NOP_EXPR, type, TREE_OPERAND (t, 0));
else
return fold_build1 (NOP_EXPR, type, t);
}
return fold_convert (type, c_objc_common_truthvalue_conversion (expr));
if (code == POINTER_TYPE || code == REFERENCE_TYPE)
return fold (convert_to_pointer (type, e));
if (code == REAL_TYPE)

View File

@ -1492,6 +1492,7 @@ pp_c_cast_expression (c_pretty_printer *pp, tree e)
case FLOAT_EXPR:
case FIX_TRUNC_EXPR:
case CONVERT_EXPR:
case NOP_EXPR:
pp_c_type_cast (pp, TREE_TYPE (e));
pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
break;
@ -1870,6 +1871,7 @@ pp_c_expression (c_pretty_printer *pp, tree e)
case FLOAT_EXPR:
case FIX_TRUNC_EXPR:
case CONVERT_EXPR:
case NOP_EXPR:
pp_c_cast_expression (pp, e);
break;
@ -1938,7 +1940,6 @@ pp_c_expression (c_pretty_printer *pp, tree e)
pp_c_right_paren (pp);
break;
case NOP_EXPR:
case NON_LVALUE_EXPR:
case SAVE_EXPR:
pp_expression (pp, TREE_OPERAND (e, 0));

View File

@ -2191,7 +2191,7 @@ build_function_call (tree function, tree params)
rhs = build_compound_literal (return_type,
build_constructor (return_type, 0));
else
rhs = fold_build1 (NOP_EXPR, return_type, integer_zero_node);
rhs = fold_convert (return_type, integer_zero_node);
return build2 (COMPOUND_EXPR, return_type, trap, rhs);
}
@ -3270,11 +3270,13 @@ build_compound_expr (tree expr1, tree expr2)
if (warn_unused_value)
{
if (VOID_TYPE_P (TREE_TYPE (expr1))
&& TREE_CODE (expr1) == CONVERT_EXPR)
&& (TREE_CODE (expr1) == NOP_EXPR
|| TREE_CODE (expr1) == CONVERT_EXPR))
; /* (void) a, b */
else if (VOID_TYPE_P (TREE_TYPE (expr1))
&& TREE_CODE (expr1) == COMPOUND_EXPR
&& TREE_CODE (TREE_OPERAND (expr1, 1)) == CONVERT_EXPR)
&& (TREE_CODE (TREE_OPERAND (expr1, 1)) == CONVERT_EXPR
|| TREE_CODE (TREE_OPERAND (expr1, 1)) == NOP_EXPR))
; /* (void) a, (void) b, c */
else
warning (0, "left-hand operand of comma expression has no effect");

View File

@ -1,3 +1,7 @@
2005-12-03 Joseph S. Myers <joseph@codesourcery.com>
* gcc.dg/cast-pretty-print-1.c: New test.
2005-12-03 Joseph S. Myers <joseph@codesourcery.com>
* gcc.dg/c90-const-expr-4.c, gcc.dg/c99-const-expr-4.c: New tests.

View File

@ -0,0 +1,12 @@
/* Test pretty-printing of casts. Should not depend on whether
NOP_EXPR or CONVERT_EXPR is used. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "" } */
int i;
void
f (void)
{
((unsigned int)i)(); /* { dg-error "error: called object '\\(unsigned int\\)i' is not a function" } */
((char)i)(); /* { dg-error "error: called object '\\(char\\)i' is not a function" } */
}