OSDN Git Service

Workaround for Itanium A/B step errata
[pf3gnuchains/gcc-fork.git] / gcc / stor-layout.c
index af219cc..8d41cd1 100644 (file)
@@ -638,6 +638,9 @@ place_field (rli, field)
   /* The type of this field.  */
   tree type = TREE_TYPE (field);
  
+  if (TREE_CODE (field) == ERROR_MARK || TREE_CODE (type) == ERROR_MARK)
+      return;
+
   /* If FIELD is static, then treat it like a separate variable, not
      really like a structure field.  If it is a FUNCTION_DECL, it's a
      method.  In both cases, all we do is lay out the decl, and we do
@@ -1054,7 +1057,7 @@ compute_record_mode (type)
       /* Must be BLKmode if any field crosses a word boundary,
         since extract_bit_field can't handle that in registers.  */
       if (bitpos / BITS_PER_WORD
-         != ((TREE_INT_CST_LOW (DECL_SIZE (field)) + bitpos - 1)
+         != ((tree_low_cst (DECL_SIZE (field), 1) + bitpos - 1)
              / BITS_PER_WORD)
          /* But there is no problem if the field is entire words.  */
          && tree_low_cst (DECL_SIZE (field), 1) % BITS_PER_WORD != 0)
@@ -1062,11 +1065,8 @@ compute_record_mode (type)
 
       /* If this field is the whole struct, remember its mode so
         that, say, we can put a double in a class into a DF
-        register instead of forcing it to live in the stack.  However,
-        we don't support using such a mode if there is no integer mode
-        of the same size, so don't set it here.  */
-      if (field == TYPE_FIELDS (type) && TREE_CHAIN (field) == 0
-         && int_mode_for_mode (DECL_MODE (field)) != BLKmode)
+        register instead of forcing it to live in the stack.  */
+      if (simple_cst_equal (TYPE_SIZE (type), DECL_SIZE (field)))
        mode = DECL_MODE (field);
 
 #ifdef STRUCT_FORCE_BLK
@@ -1077,8 +1077,9 @@ compute_record_mode (type)
 #endif /* STRUCT_FORCE_BLK  */
     }
 
-  if (mode != VOIDmode)
-    /* We only have one real field; use its mode.  */
+  /* If we only have one real field; use its mode.  This only applies to
+     RECORD_TYPE.  This does not apply to unions.  */
+  if (TREE_CODE (type) == RECORD_TYPE && mode != VOIDmode)
     TYPE_MODE (type) = mode;
   else
     TYPE_MODE (type) = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1);
@@ -1227,8 +1228,6 @@ void
 layout_type (type)
      tree type;
 {
-  int old;
-
   if (type == 0)
     abort ();
 
@@ -1236,16 +1235,6 @@ layout_type (type)
   if (TYPE_SIZE (type))
     return;
 
-  /* Make sure all nodes we allocate are not momentary; they must last
-     past the current statement.  */
-  old = suspend_momentary ();
-
-  /* Put all our nodes into the same obstack as the type.  Also,
-     make expressions saveable (this is a no-op for permanent types).  */
-
-  push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
-  saveable_allocation ();
-
   switch (TREE_CODE (type))
     {
     case LANG_TYPE:
@@ -1345,22 +1334,6 @@ layout_type (type)
            tree length;
            tree element_size;
 
-           /* If UB is max (lb - 1, x), remove the MAX_EXPR since the
-              test for negative below covers it.  */
-           if (TREE_CODE (ub) == MAX_EXPR
-               && TREE_CODE (TREE_OPERAND (ub, 0)) == MINUS_EXPR
-               && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 0), 1))
-               && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 0), 0),
-                                   lb, 0))
-             ub = TREE_OPERAND (ub, 1);
-           else if (TREE_CODE (ub) == MAX_EXPR
-                    && TREE_CODE (TREE_OPERAND (ub, 1)) == MINUS_EXPR
-                    && integer_onep (TREE_OPERAND (TREE_OPERAND (ub, 1), 1))
-                    && operand_equal_p (TREE_OPERAND (TREE_OPERAND (ub, 1),
-                                                      0),
-                                        lb, 0))
-             ub = TREE_OPERAND (ub, 0);
-
            /* The initial subtraction should happen in the original type so
               that (possible) negative values are handled appropriately.  */
            length = size_binop (PLUS_EXPR, size_one_node,
@@ -1369,23 +1342,17 @@ layout_type (type)
                                                       TREE_TYPE (lb),
                                                       ub, lb))));
 
-           /* If neither bound is a constant and sizetype is signed, make
-              sure the size is never negative.  We should really do this
-              if *either* bound is non-constant, but this is the best
-              compromise between C and Ada.  */
-           if (! TREE_UNSIGNED (sizetype)
-               && TREE_CODE (TYPE_MIN_VALUE (index)) != INTEGER_CST
-               && TREE_CODE (TYPE_MAX_VALUE (index)) != INTEGER_CST)
-             length = size_binop (MAX_EXPR, length, size_zero_node);
-
            /* Special handling for arrays of bits (for Chill).  */
            element_size = TYPE_SIZE (element);
-           if (TYPE_PACKED (type) && INTEGRAL_TYPE_P (element))
+           if (TYPE_PACKED (type) && INTEGRAL_TYPE_P (element)
+               && (integer_zerop (TYPE_MAX_VALUE (element))
+                   || integer_onep (TYPE_MAX_VALUE (element)))
+               && host_integerp (TYPE_MIN_VALUE (element), 1))
              {
                HOST_WIDE_INT maxvalue
-                 = TREE_INT_CST_LOW (TYPE_MAX_VALUE (element));
+                 = tree_low_cst (TYPE_MAX_VALUE (element), 1);
                HOST_WIDE_INT minvalue
-                 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (element));
+                 = tree_low_cst (TYPE_MIN_VALUE (element), 1);
 
                if (maxvalue - minvalue == 1
                    && (maxvalue == 1 || maxvalue == 0))
@@ -1533,13 +1500,18 @@ layout_type (type)
       && TREE_CODE (type) != QUAL_UNION_TYPE)
     finalize_type_size (type);
 
-  pop_obstacks ();
-  resume_momentary (old);
-
   /* If this type is created before sizetype has been permanently set,
      record it so set_sizetype can fix it up.  */
   if (! sizetype_set)
     early_type_list = tree_cons (NULL_TREE, type, early_type_list);
+
+  /* If an alias set has been set for this aggregate when it was incomplete,
+     force it into alias set 0.
+     This is too conservative, but we cannot call record_component_aliases
+     here because some frontends still change the aggregates after
+     layout_type.  */
+  if (AGGREGATE_TYPE_P (type) && TYPE_ALIAS_SET_KNOWN_P (type))
+    TYPE_ALIAS_SET (type) = 0;
 }
 \f
 /* Create and return a type for signed integers of PRECISION bits.  */