]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-common.c (c_sizeof_or_alignof_type): Use fold_convert instead of building a NOP_EXPR.
authorJoseph Myers <joseph@codesourcery.com>
Sat, 3 Dec 2005 18:58:43 +0000 (18:58 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sat, 3 Dec 2005 18:58:43 +0000 (18:58 +0000)
* 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
gcc/c-common.c
gcc/c-convert.c
gcc/c-pretty-print.c
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cast-pretty-print-1.c [new file with mode: 0644]

index 31b633e60aa1f21211a2de4f76f95c22b5dc3644..afe22a09faa293f08b0192963dff4607386d3f31 100644 (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
index e61709459589c1131fd6fa24623eb4dae6e82040..898f3944d0234cc573701cb9eddb60bd421fa285 100644 (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);
 }
 \f
 /* Handle C and C++ default attributes.  */
index 50bb923bae26e1df0fe61a24a1ddce41524db312..bf306c8ea2fe7e55be4e199a8a1322fc06a245d6 100644 (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)
index 5e67a96cf4e5d33eb3ccddaedf1884dc55f3dc28..6618a70b7b1c95d20a9291916ea3dcdc84931e1d 100644 (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));
index 188e1fe355c706481f29436bf6359e0d344e34e6..8b8eb56ea4424cb70f12a97a2ee04ed04e4d2798 100644 (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");
index b6c4a8e1e1f934d2f98428d79457734240f01f4f..257c74a5d1a4392ceca237a987598fe190af1b53 100644 (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.
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 (file)
index 0000000..e5ecec1
--- /dev/null
@@ -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" } */
+}