OSDN Git Service

Update FSF address.
[pf3gnuchains/gcc-fork.git] / gcc / fold-const.c
index 644807d..7238e7a 100644 (file)
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 /*@@ This file should be rewritten to use an arbitrary precision
   @@ representation for "struct tree_int_cst" and "struct tree_real_cst".
@@ -337,8 +338,10 @@ lshift_double (l1, h1, count, prec, lv, hv, arith)
       return;
     }
   
-  if (count >= prec)
-    count = (unsigned HOST_WIDE_INT) count & prec;
+#ifdef SHIFT_COUNT_TRUNCATED
+  if (SHIFT_COUNT_TRUNCATED)
+    count %= prec;
+#endif
 
   if (count >= HOST_BITS_PER_WIDE_INT)
     {
@@ -370,8 +373,10 @@ rshift_double (l1, h1, count, prec, lv, hv, arith)
              ? -((unsigned HOST_WIDE_INT) h1 >> (HOST_BITS_PER_WIDE_INT - 1))
              : 0);
 
-  if (count >= prec)
-    count = (unsigned HOST_WIDE_INT) count % prec;
+#ifdef SHIFT_COUNT_TRUNCATED
+  if (SHIFT_COUNT_TRUNCATED)
+    count %= prec;
+#endif
 
   if (count >= HOST_BITS_PER_WIDE_INT)
     {
@@ -1133,7 +1138,7 @@ const_binop (code, arg1, arg2, notrunc)
     got_it:
       TREE_TYPE (t) = TREE_TYPE (arg1);
       TREE_OVERFLOW (t)
-       = ((notrunc ? !uns && overflow : force_fit_type (t, overflow))
+       = ((notrunc ? !uns && overflow : force_fit_type (t, overflow && !uns))
           | TREE_OVERFLOW (arg1)
           | TREE_OVERFLOW (arg2));
       TREE_CONSTANT_OVERFLOW (t) = (TREE_OVERFLOW (t)
@@ -2088,6 +2093,10 @@ invert_truthvalue (arg)
 
     case SAVE_EXPR:
       return build1 (TRUTH_NOT_EXPR, type, arg);
+
+    case CLEANUP_POINT_EXPR:
+      return build1 (CLEANUP_POINT_EXPR, type,
+                    invert_truthvalue (TREE_OPERAND (arg, 0)));
     }
   if (TREE_CODE (TREE_TYPE (arg)) != BOOLEAN_TYPE)
     abort ();
@@ -2611,7 +2620,7 @@ range_test (jcode, type, lo_code, hi_code, var, lo_cst, hi_cst)
 }
 \f
 /* Subroutine for fold_truthop: C is an INTEGER_CST interpreted as a P
-   bit value.  Arrange things so the extra bits will be set to zero if and]
+   bit value.  Arrange things so the extra bits will be set to zero if and
    only if C is signed-extended to its full width.  */
 
 static tree
@@ -2631,7 +2640,7 @@ unextend (c, p, unsignedp)
     c = convert (signed_type (type), c);
 
   /* We work by getting just the sign bit into the low-order bit, then
-     into the high-order bit, then sign-extened.  We then XOR that value
+     into the high-order bit, then sign-extend.  We then XOR that value
      with C.  */
   temp = const_binop (RSHIFT_EXPR, c, size_int (p - 1), 0);
   temp = const_binop (BIT_AND_EXPR, temp, size_int (1), 0);
@@ -3266,9 +3275,10 @@ fold (expr)
            }
          else
            {
+             tree testtype = TREE_TYPE (arg1);
              test = arg1;
-             true_value = integer_one_node;
-             false_value = integer_zero_node;
+             true_value = convert (testtype, integer_one_node);
+             false_value = convert (testtype, integer_zero_node);
            }
 
          /* If ARG0 is complex we want to make sure we only evaluate
@@ -3277,7 +3287,7 @@ fold (expr)
             succeed in folding one part to a constant, we do not need
             to make this SAVE_EXPR.  Since we do this optimization
             primarily to see if we do end up with constant and this
-            SAVE_EXPR interfers with later optimizations, suppressing
+            SAVE_EXPR interferes with later optimizations, suppressing
             it when we can is important.  */
 
          if (TREE_CODE (arg0) != SAVE_EXPR
@@ -3321,9 +3331,10 @@ fold (expr)
            }
          else
            {
+             tree testtype = TREE_TYPE (arg0);
              test = arg0;
-             true_value = integer_one_node;
-             false_value = integer_zero_node;
+             true_value = convert (testtype, integer_one_node);
+             false_value = convert (testtype, integer_zero_node);
            }
 
          if (TREE_CODE (arg1) != SAVE_EXPR
@@ -4197,7 +4208,11 @@ fold (expr)
         and its values must be 0 or 1.
         ("true" is a fixed value perhaps depending on the language,
         but we don't handle values other than 1 correctly yet.)  */
-      return invert_truthvalue (arg0);
+      tem = invert_truthvalue (arg0);
+      /* Avoid infinite recursion.  */
+      if (TREE_CODE (tem) == TRUTH_NOT_EXPR)
+       return t;
+      return convert (type, tem);
 
     case TRUTH_ANDIF_EXPR:
       /* Note that the operands of this must be ints
@@ -4840,12 +4855,16 @@ fold (expr)
              case GE_EXPR:
              case GT_EXPR:
                return pedantic_non_lvalue
-                 (fold (build1 (ABS_EXPR, type, arg1)));
+                 (convert (type, fold (build1 (ABS_EXPR,
+                                               TREE_TYPE (arg1), arg1))));
              case LE_EXPR:
              case LT_EXPR:
                return pedantic_non_lvalue
                  (fold (build1 (NEGATE_EXPR, type,
-                                fold (build1 (ABS_EXPR, type, arg1)))));
+                                convert (type,
+                                         fold (build1 (ABS_EXPR,
+                                                       TREE_TYPE (arg1),
+                                                       arg1))))));
              }
 
          /* If this is A != 0 ? A : 0, this is simply A.  For ==, it is