summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2005-12-03 18:58:43 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2005-12-03 18:58:43 +0000
commit143d62d7b00994db0ebf403b7bf9c3ce50bfc00f (patch)
tree8a5a86529d5c77ec43f37dd146c1b7272877a41c
parent90ba46222fda6f62279bd62fca3e236a2caaea46 (diff)
downloadgcc-143d62d7b00994db0ebf403b7bf9c3ce50bfc00f.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@108001 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog16
-rw-r--r--gcc/c-common.c6
-rw-r--r--gcc/c-convert.c23
-rw-r--r--gcc/c-pretty-print.c3
-rw-r--r--gcc/c-typeck.c8
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/cast-pretty-print-1.c12
7 files changed, 45 insertions, 27 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 31b633e60aa..afe22a09faa 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-common.c b/gcc/c-common.c
index e6170945958..898f3944d02 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 50bb923bae2..bf306c8ea2f 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 5e67a96cf4e..6618a70b7b1 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 188e1fe355c..8b8eb56ea44 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 b6c4a8e1e1f..257c74a5d1a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
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.
2005-12-02 Mark Mitchell <mark@codesourcery.com>
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 00000000000..e5ecec1a096
--- /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 <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" } */
+}