OSDN Git Service

* tree-ssa-ccp.c (maybe_fold_offset_to_component_ref): Always subtract
authorrakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Jan 2005 21:09:25 +0000 (21:09 +0000)
committerrakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Jan 2005 21:09:25 +0000 (21:09 +0000)
the offset of the selected field.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@93918 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/tree-ssa-ccp.c

index 9b7b9b5..77867e8 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-19  Zdenek Dvorak  <dvorakz@suse.cz>
+
+       * tree-ssa-ccp.c (maybe_fold_offset_to_component_ref): Always subtract
+       the offset of the selected field.
+
 2005-01-19  Kazu Hirata  <kazu@cs.umass.edu>
 
        * tree-cfg.c (remove_forwarder_block): Fix the check to
index c530ede..697e97e 100644 (file)
@@ -1449,45 +1449,39 @@ maybe_fold_offset_to_component_ref (tree record_type, tree base, tree offset,
        continue;
 
       field_type = TREE_TYPE (f);
-      if (cmp < 0)
-       {
-         /* Don't care about offsets into the middle of scalars.  */
-         if (!AGGREGATE_TYPE_P (field_type))
-           continue;
-
-         /* Check for array at the end of the struct.  This is often
-            used as for flexible array members.  We should be able to
-            turn this into an array access anyway.  */
-         if (TREE_CODE (field_type) == ARRAY_TYPE)
-           tail_array_field = f;
-
-         /* Check the end of the field against the offset.  */
-         if (!DECL_SIZE_UNIT (f)
-             || TREE_CODE (DECL_SIZE_UNIT (f)) != INTEGER_CST)
-           continue;
-         t = int_const_binop (MINUS_EXPR, offset, DECL_FIELD_OFFSET (f), 1);
-         if (!tree_int_cst_lt (t, DECL_SIZE_UNIT (f)))
-           continue;
-
-         /* If we matched, then set offset to the displacement into
-            this field.  */
-         offset = t;
-       }
 
       /* Here we exactly match the offset being checked.  If the types match,
         then we can return that field.  */
-      else if (lang_hooks.types_compatible_p (orig_type, field_type))
+      if (cmp == 0
+         && lang_hooks.types_compatible_p (orig_type, field_type))
        {
          if (base_is_ptr)
            base = build1 (INDIRECT_REF, record_type, base);
          t = build (COMPONENT_REF, field_type, base, f, NULL_TREE);
          return t;
        }
+      
+      /* Don't care about offsets into the middle of scalars.  */
+      if (!AGGREGATE_TYPE_P (field_type))
+       continue;
 
-      /* Don't care about type-punning of scalars.  */
-      else if (!AGGREGATE_TYPE_P (field_type))
-       return NULL_TREE;
+      /* Check for array at the end of the struct.  This is often
+        used as for flexible array members.  We should be able to
+        turn this into an array access anyway.  */
+      if (TREE_CODE (field_type) == ARRAY_TYPE)
+       tail_array_field = f;
+
+      /* Check the end of the field against the offset.  */
+      if (!DECL_SIZE_UNIT (f)
+         || TREE_CODE (DECL_SIZE_UNIT (f)) != INTEGER_CST)
+       continue;
+      t = int_const_binop (MINUS_EXPR, offset, field_offset, 1);
+      if (!tree_int_cst_lt (t, DECL_SIZE_UNIT (f)))
+       continue;
 
+      /* If we matched, then set offset to the displacement into
+        this field.  */
+      offset = t;
       goto found;
     }
 
@@ -1496,6 +1490,7 @@ maybe_fold_offset_to_component_ref (tree record_type, tree base, tree offset,
 
   f = tail_array_field;
   field_type = TREE_TYPE (f);
+  offset = int_const_binop (MINUS_EXPR, offset, byte_position (f), 1);
 
  found:
   /* If we get here, we've got an aggregate field, and a possibly