From 4c7a6c1bdb63272d47cbe9aa39b2ee64d3a63fa4 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Sat, 3 Dec 2005 18:58:43 +0000 Subject: [PATCH] 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 --- gcc/ChangeLog | 16 +++++++++++++++ gcc/c-common.c | 6 +++--- gcc/c-convert.c | 23 +++------------------- gcc/c-pretty-print.c | 3 ++- gcc/c-typeck.c | 8 +++++--- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/cast-pretty-print-1.c | 12 +++++++++++ 7 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cast-pretty-print-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 31b633e60aa1..afe22a09faa2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2005-12-03 Joseph S. Myers + + * 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 PR rtl-optimization/25197 diff --git a/gcc/c-common.c b/gcc/c-common.c index e61709459589..898f3944d023 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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. */ diff --git a/gcc/c-convert.c b/gcc/c-convert.c index 50bb923bae26..bf306c8ea2fe 100644 --- a/gcc/c-convert.c +++ b/gcc/c-convert.c @@ -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) diff --git a/gcc/c-pretty-print.c b/gcc/c-pretty-print.c index 5e67a96cf4e5..6618a70b7b1c 100644 --- a/gcc/c-pretty-print.c +++ b/gcc/c-pretty-print.c @@ -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)); diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 188e1fe355c7..8b8eb56ea442 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b6c4a8e1e1f9..257c74a5d1a4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-12-03 Joseph S. Myers + + * gcc.dg/cast-pretty-print-1.c: New test. + 2005-12-03 Joseph S. Myers * gcc.dg/c90-const-expr-4.c, gcc.dg/c99-const-expr-4.c: New tests. diff --git a/gcc/testsuite/gcc.dg/cast-pretty-print-1.c b/gcc/testsuite/gcc.dg/cast-pretty-print-1.c new file mode 100644 index 000000000000..e5ecec1a096a --- /dev/null +++ b/gcc/testsuite/gcc.dg/cast-pretty-print-1.c @@ -0,0 +1,12 @@ +/* Test pretty-printing of casts. Should not depend on whether + NOP_EXPR or CONVERT_EXPR is used. */ +/* Origin: Joseph Myers */ +/* { 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" } */ +} -- 2.47.2