]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/convert.c
(convert_to_integer): Don't pass truncate into ABS_EXPR.
[gcc.git] / gcc / convert.c
index a063a6e88e109f6585c1880c29cf401708febb0b..032bb516899351f59e5fd633e83d1464a9c88c28 100644 (file)
@@ -100,7 +100,7 @@ convert_to_real (type, expr)
   {
     register tree tem = make_node (REAL_CST);
     TREE_TYPE (tem) = type;
-    TREE_REAL_CST (tem) = REAL_VALUE_ATOF ("0.0");
+    TREE_REAL_CST (tem) = REAL_VALUE_ATOF ("0.0", TYPE_MODE (type));
     return tem;
   }
 }
@@ -199,11 +199,22 @@ convert_to_integer (type, expr)
                /* In this case, shifting is like multiplication.  */
                goto trunc1;
              else
-               /* If it is >= that width, result is zero.
-                  Handling this with trunc1 would give the wrong result:
-                  (int) ((long long) a << 32) is well defined (as 0)
-                  but (int) a << 32 is undefined and would get a warning.  */
-               return convert_to_integer (type, integer_zero_node);
+               {
+                 /* If it is >= that width, result is zero.
+                    Handling this with trunc1 would give the wrong result:
+                    (int) ((long long) a << 32) is well defined (as 0)
+                    but (int) a << 32 is undefined and would get a
+                    warning.  */
+
+                 tree t = convert_to_integer (type, integer_zero_node);
+
+                 /* If the original expression had side-effects, we must
+                    preserve it.  */
+                 if (TREE_SIDE_EFFECTS (expr))
+                   return build (COMPOUND_EXPR, type, expr, t);
+                 else
+                   return t;
+               }
            }
          break;
 
@@ -269,10 +280,10 @@ convert_to_integer (type, expr)
                              || TREE_UNSIGNED (TREE_TYPE (arg1)))
                             ? unsigned_type (typex) : signed_type (typex));
                    return convert (type,
-                                   build_binary_op (ex_form,
-                                                    convert (typex, arg0),
-                                                    convert (typex, arg1),
-                                                    0));
+                                   fold (build (ex_form, typex,
+                                                convert (typex, arg0),
+                                                convert (typex, arg1),
+                                                0)));
                  }
              }
          }
@@ -280,7 +291,8 @@ convert_to_integer (type, expr)
 
        case NEGATE_EXPR:
        case BIT_NOT_EXPR:
-       case ABS_EXPR:
+         /* This is not correct for ABS_EXPR,
+            since we must test the sign before truncation.  */
          {
            register tree typex = type;
 
@@ -300,9 +312,9 @@ convert_to_integer (type, expr)
                typex = (TREE_UNSIGNED (TREE_TYPE (expr))
                         ? unsigned_type (typex) : signed_type (typex));
                return convert (type,
-                               build_unary_op (ex_form,
-                                               convert (typex, TREE_OPERAND (expr, 0)),
-                                               1));
+                               fold (build1 (ex_form, typex,
+                                             convert (typex,
+                                                      TREE_OPERAND (expr, 0)))));
              }
          }
 
@@ -411,9 +423,13 @@ convert_to_complex (type, expr)
          return fold (build (COMPLEX_EXPR,
                              type,
                              convert (subtype,
-                                      build_unary_op (REALPART_EXPR, expr, 1)),
+                                      fold (build1 (REALPART_EXPR,
+                                                    TREE_TYPE (TREE_TYPE (expr)),
+                                                    expr))),
                              convert (subtype,
-                                      build_unary_op (IMAGPART_EXPR, expr, 1))));
+                                      fold (build1 (IMAGPART_EXPR,
+                                                    TREE_TYPE (TREE_TYPE (expr)),
+                                                    expr)))));
        }
     }
 
This page took 0.030795 seconds and 5 git commands to generate.