OSDN Git Service

* config/bfin/bfin.h (PARM_BOUNDRY, STACK_BOUNDRY): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / convert.c
index e8030bf..9797704 100644 (file)
@@ -1,6 +1,6 @@
 /* Utility routines for data type conversion for GCC.
    Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1997, 1998,
-   2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -33,27 +33,35 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 #include "toplev.h"
 #include "langhooks.h"
 #include "real.h"
-/* Convert EXPR to some pointer or reference type TYPE.
 
+/* Convert EXPR to some pointer or reference type TYPE.
    EXPR must be pointer, reference, integer, enumeral, or literal zero;
    in other cases error is called.  */
 
 tree
 convert_to_pointer (tree type, tree expr)
 {
+  if (TREE_TYPE (expr) == type)
+    return expr;
+
   if (integer_zerop (expr))
-    return build_int_cst (type, 0);
+    {
+      tree t = build_int_cst (type, 0);
+      if (TREE_OVERFLOW (expr) || TREE_CONSTANT_OVERFLOW (expr))
+       t = force_fit_type (t, 0, TREE_OVERFLOW (expr),
+                           TREE_CONSTANT_OVERFLOW (expr));
+      return t;
+    }
 
   switch (TREE_CODE (TREE_TYPE (expr)))
     {
     case POINTER_TYPE:
     case REFERENCE_TYPE:
-      return build1 (NOP_EXPR, type, expr);
+      return fold_build1 (NOP_EXPR, type, expr);
 
     case INTEGER_TYPE:
     case ENUMERAL_TYPE:
     case BOOLEAN_TYPE:
-    case CHAR_TYPE:
       if (TYPE_PRECISION (TREE_TYPE (expr)) != POINTER_SIZE)
        expr = fold_build1 (NOP_EXPR,
                             lang_hooks.types.type_for_size (POINTER_SIZE, 0),
@@ -313,7 +321,6 @@ convert_to_real (tree type, tree expr)
     case INTEGER_TYPE:
     case ENUMERAL_TYPE:
     case BOOLEAN_TYPE:
-    case CHAR_TYPE:
       return build1 (FLOAT_EXPR, type, expr);
 
     case COMPLEX_TYPE:
@@ -447,7 +454,6 @@ convert_to_integer (tree type, tree expr)
     case INTEGER_TYPE:
     case ENUMERAL_TYPE:
     case BOOLEAN_TYPE:
-    case CHAR_TYPE:
       /* If this is a logical operation, which just returns 0 or 1, we can
         change the type of the expression.  */
 
@@ -628,7 +634,17 @@ convert_to_integer (tree type, tree expr)
                                || ex_form == RSHIFT_EXPR
                                || ex_form == LROTATE_EXPR
                                || ex_form == RROTATE_EXPR))
-                       || ex_form == LSHIFT_EXPR)
+                       || ex_form == LSHIFT_EXPR
+                       /* If we have !flag_wrapv, and either ARG0 or
+                          ARG1 is of a signed type, we have to do
+                          PLUS_EXPR or MINUS_EXPR in an unsigned
+                          type.  Otherwise, we would introduce
+                          signed-overflow undefinedness.  */
+                       || (!flag_wrapv
+                           && (ex_form == PLUS_EXPR
+                               || ex_form == MINUS_EXPR)
+                           && (!TYPE_UNSIGNED (TREE_TYPE (arg0))
+                               || !TYPE_UNSIGNED (TREE_TYPE (arg1)))))
                      typex = lang_hooks.types.unsigned_type (typex);
                    else
                      typex = lang_hooks.types.signed_type (typex);
@@ -719,7 +735,6 @@ convert_to_complex (tree type, tree expr)
     case INTEGER_TYPE:
     case ENUMERAL_TYPE:
     case BOOLEAN_TYPE:
-    case CHAR_TYPE:
       return build2 (COMPLEX_EXPR, type, convert (subtype, expr),
                     convert (subtype, integer_zero_node));