OSDN Git Service

2007-06-29 Tobias Burnus <burnus@net-b.de>
[pf3gnuchains/gcc-fork.git] / gcc / convert.c
index 11d8492..0c7c108 100644 (file)
@@ -1,6 +1,7 @@
 /* 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, 2006 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -46,8 +47,7 @@ convert_to_pointer (tree type, tree expr)
 
   /* Propagate overflow to the NULL pointer.  */
   if (integer_zerop (expr))
-    return force_fit_type_double (type, 0, 0, 0, TREE_OVERFLOW (expr),
-                                 TREE_CONSTANT_OVERFLOW (expr));
+    return force_fit_type_double (type, 0, 0, 0, TREE_OVERFLOW (expr));
 
   switch (TREE_CODE (TREE_TYPE (expr)))
     {
@@ -173,7 +173,7 @@ convert_to_real (tree type, tree expr)
          CASE_MATHFN (Y1)
 #undef CASE_MATHFN
            {
-             tree arg0 = strip_float_extensions (TREE_VALUE (TREE_OPERAND (expr, 1)));
+             tree arg0 = strip_float_extensions (CALL_EXPR_ARG (expr, 0));
              tree newtype = type;
 
              /* We have (outertype)sqrt((innertype)x).  Choose the wider mode from
@@ -188,13 +188,12 @@ convert_to_real (tree type, tree expr)
                  && (TYPE_MODE (newtype) == TYPE_MODE (double_type_node)
                      || TYPE_MODE (newtype) == TYPE_MODE (float_type_node)))
                {
-                 tree arglist;
                  tree fn = mathfn_built_in (newtype, fcode);
 
                  if (fn)
                  {
-                   arglist = build_tree_list (NULL_TREE, fold (convert_to_real (newtype, arg0)));
-                   expr = build_function_call_expr (fn, arglist);
+                   tree arg = fold (convert_to_real (newtype, arg0));
+                   expr = build_call_expr (fn, 1, arg);
                    if (newtype == type)
                      return expr;
                  }
@@ -225,18 +224,14 @@ convert_to_real (tree type, tree expr)
 
       if (fn)
        {
-         tree arg
-           = strip_float_extensions (TREE_VALUE (TREE_OPERAND (expr, 1)));
+         tree arg = strip_float_extensions (CALL_EXPR_ARG (expr, 0));
 
          /* Make sure (type)arg0 is an extension, otherwise we could end up
             changing (float)floor(double d) into floorf((float)d), which is
             incorrect because (float)d uses round-to-nearest and can round
             up to the next integer.  */
          if (TYPE_PRECISION (type) >= TYPE_PRECISION (TREE_TYPE (arg)))
-           return
-             build_function_call_expr (fn,
-                                       build_tree_list (NULL_TREE,
-                                         fold (convert_to_real (type, arg))));
+           return build_call_expr (fn, 1, fold (convert_to_real (type, arg)));
        }
     }
 
@@ -418,12 +413,12 @@ convert_to_integer (tree type, tree expr)
            fn = mathfn_built_in (s_intype, BUILT_IN_LLROUND);
          break;
 
-       CASE_FLT_FN (BUILT_IN_RINT):
-         /* Only convert rint* if we can ignore math exceptions.  */
+       CASE_FLT_FN (BUILT_IN_NEARBYINT):
+         /* Only convert nearbyint* if we can ignore math exceptions.  */
          if (flag_trapping_math)
            break;
          /* ... Fall through ...  */
-       CASE_FLT_FN (BUILT_IN_NEARBYINT):
+       CASE_FLT_FN (BUILT_IN_RINT):
          if (outprec < TYPE_PRECISION (long_integer_type_node)
              || (outprec == TYPE_PRECISION (long_integer_type_node)
                  && !TYPE_UNSIGNED (type)))
@@ -434,10 +429,7 @@ convert_to_integer (tree type, tree expr)
          break;
 
        CASE_FLT_FN (BUILT_IN_TRUNC):
-         {
-           tree arglist = TREE_OPERAND (s_expr, 1);
-           return convert_to_integer (type, TREE_VALUE (arglist));
-         }
+         return convert_to_integer (type, CALL_EXPR_ARG (s_expr, 0));
 
        default:
          break;
@@ -445,8 +437,7 @@ convert_to_integer (tree type, tree expr)
       
       if (fn)
         {
-         tree arglist = TREE_OPERAND (s_expr, 1);
-         tree newexpr = build_function_call_expr (fn, arglist);
+         tree newexpr = build_call_expr (fn, 1, CALL_EXPR_ARG (s_expr, 0));
          return convert_to_integer (type, newexpr);
        }
     }
@@ -661,14 +652,13 @@ convert_to_integer (tree type, tree expr)
                           PLUS_EXPR or MINUS_EXPR in an unsigned
                           type.  Otherwise, we would introduce
                           signed-overflow undefinedness.  */
-                       || (!flag_wrapv
+                       || ((!TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0))
+                            || !TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1)))
                            && (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);
+                               || ex_form == MINUS_EXPR)))
+                     typex = unsigned_type_for (typex);
                    else
-                     typex = lang_hooks.types.signed_type (typex);
+                     typex = signed_type_for (typex);
                    return convert (type,
                                    fold_build2 (ex_form, typex,
                                                 convert (typex, arg0),
@@ -688,9 +678,9 @@ convert_to_integer (tree type, tree expr)
            /* Don't do unsigned arithmetic where signed was wanted,
               or vice versa.  */
            if (TYPE_UNSIGNED (TREE_TYPE (expr)))
-             typex = lang_hooks.types.unsigned_type (type);
+             typex = unsigned_type_for (type);
            else
-             typex = lang_hooks.types.signed_type (type);
+             typex = signed_type_for (type);
            return convert (type,
                            fold_build1 (ex_form, typex,
                                         convert (typex,