OSDN Git Service

Joseph Myers <joseph@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / fold-const.c
index 8be8f3e..25ab487 100644 (file)
@@ -53,6 +53,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "expr.h"
 #include "tm_p.h"
 #include "target.h"
+#include "diagnostic-core.h"
 #include "toplev.h"
 #include "intl.h"
 #include "ggc.h"
@@ -2043,7 +2044,6 @@ maybe_lvalue_p (const_tree x)
   case COMPONENT_REF:
   case MEM_REF:
   case INDIRECT_REF:
-  case MISALIGNED_INDIRECT_REF:
   case ARRAY_REF:
   case ARRAY_RANGE_REF:
   case BIT_FIELD_REF:
@@ -2586,20 +2586,22 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
       switch (TREE_CODE (arg0))
        {
        case INDIRECT_REF:
-       case MISALIGNED_INDIRECT_REF:
        case REALPART_EXPR:
        case IMAGPART_EXPR:
          return OP_SAME (0);
 
        case MEM_REF:
-         /* Require equal access sizes.  We can have incomplete types
-            for array references of variable-sized arrays from the
-            Fortran frontent though.  */
+         /* Require equal access sizes, and similar pointer types.
+            We can have incomplete types for array references of
+            variable-sized arrays from the Fortran frontent
+            though.  */
          return ((TYPE_SIZE (TREE_TYPE (arg0)) == TYPE_SIZE (TREE_TYPE (arg1))
                   || (TYPE_SIZE (TREE_TYPE (arg0))
                       && TYPE_SIZE (TREE_TYPE (arg1))
                       && operand_equal_p (TYPE_SIZE (TREE_TYPE (arg0)),
                                           TYPE_SIZE (TREE_TYPE (arg1)), flags)))
+                 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg0, 1)))
+                     == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg1, 1))))
                  && OP_SAME (0) && OP_SAME (1));
 
        case ARRAY_REF:
@@ -3984,9 +3986,9 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
          n_high = range_binop (MINUS_EXPR, exp_type,
                                build_int_cst (exp_type, 0),
                                0, low, 0);
-         low = n_low, high = n_high;
-         exp = arg0;
-         continue;
+         if (n_high != 0 && TREE_OVERFLOW (n_high))
+           break;
+         goto normalize;
 
        case BIT_NOT_EXPR:
          /* ~ X -> -X - 1  */
@@ -4020,6 +4022,7 @@ make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
          if (TYPE_OVERFLOW_UNDEFINED (arg0_type))
            *strict_overflow_p = true;
 
+       normalize:
          /* Check for an unsigned range which has wrapped around the maximum
             value thus making n_high < n_low, and normalize it.  */
          if (n_low && n_high && tree_int_cst_lt (n_high, n_low))
@@ -7595,8 +7598,7 @@ build_fold_addr_expr_with_type_loc (location_t loc, tree t, tree ptrtype)
   if (TREE_CODE (t) == WITH_SIZE_EXPR)
     t = TREE_OPERAND (t, 0);
 
-  if (TREE_CODE (t) == INDIRECT_REF
-      || TREE_CODE (t) == MISALIGNED_INDIRECT_REF)
+  if (TREE_CODE (t) == INDIRECT_REF)
     {
       t = TREE_OPERAND (t, 0);
 
@@ -8681,6 +8683,7 @@ fold_comparison (location_t loc, enum tree_code code, tree type,
       else if (TREE_CODE (arg0) == POINTER_PLUS_EXPR)
        {
          base0 = TREE_OPERAND (arg0, 0);
+         STRIP_SIGN_NOPS (base0);
          if (TREE_CODE (base0) == ADDR_EXPR)
            {
              base0 = TREE_OPERAND (base0, 0);
@@ -8703,6 +8706,7 @@ fold_comparison (location_t loc, enum tree_code code, tree type,
       else if (TREE_CODE (arg1) == POINTER_PLUS_EXPR)
        {
          base1 = TREE_OPERAND (arg1, 0);
+         STRIP_SIGN_NOPS (base1);
          if (TREE_CODE (base1) == ADDR_EXPR)
            {
              base1 = TREE_OPERAND (base1, 0);
@@ -13644,7 +13648,7 @@ fold_check_failed (const_tree expr ATTRIBUTE_UNUSED, const_tree ret ATTRIBUTE_UN
 static void
 fold_checksum_tree (const_tree expr, struct md5_ctx *ctx, htab_t ht)
 {
-  const void **slot;
+  void **slot;
   enum tree_code code;
   union tree_node buf;
   int i, len;
@@ -13656,10 +13660,10 @@ recursive_label:
              && sizeof (struct tree_type) <= sizeof (struct tree_function_decl));
   if (expr == NULL)
     return;
-  slot = (const void **) htab_find_slot (ht, expr, INSERT);
+  slot = (void **) htab_find_slot (ht, expr, INSERT);
   if (*slot != NULL)
     return;
-  *slot = expr;
+  *slot = CONST_CAST_TREE (expr);
   code = TREE_CODE (expr);
   if (TREE_CODE_CLASS (code) == tcc_declaration
       && DECL_ASSEMBLER_NAME_SET_P (expr))