OSDN Git Service

fix off one error for one for all.
[pf3gnuchains/gcc-fork.git] / gcc / stor-layout.c
index 403f8ab..728b70b 100644 (file)
@@ -344,7 +344,8 @@ do_type_align (tree type, tree decl)
   if (TYPE_ALIGN (type) > DECL_ALIGN (decl))
     {
       DECL_ALIGN (decl) = TYPE_ALIGN (type);
-      DECL_USER_ALIGN (decl) = TYPE_USER_ALIGN (type);
+      if (TREE_CODE (decl) == FIELD_DECL)
+       DECL_USER_ALIGN (decl) = TYPE_USER_ALIGN (type);
     }
 }
 
@@ -515,10 +516,10 @@ layout_decl (tree decl, unsigned int known_align)
          int size_as_int = TREE_INT_CST_LOW (size);
 
          if (compare_tree_int (size, size_as_int) == 0)
-           warning_with_decl (decl, "size of `%s' is %d bytes", size_as_int);
+           warning ("%Jsize of '%D' is %d bytes", decl, decl, size_as_int);
          else
-           warning_with_decl (decl, "size of `%s' is larger than %d bytes",
-                              larger_than_size);
+           warning ("%Jsize of '%D' is larger than %d bytes",
+                     decl, decl, larger_than_size);
        }
     }
 
@@ -553,8 +554,7 @@ set_lang_adjust_rli (void (*f) (record_layout_info))
 record_layout_info
 start_record_layout (tree t)
 {
-  record_layout_info rli
-    = (record_layout_info) xmalloc (sizeof (struct record_layout_info_s));
+  record_layout_info rli = xmalloc (sizeof (struct record_layout_info_s));
 
   rli->t = t;
 
@@ -884,9 +884,11 @@ place_field (record_layout_info rli, tree field)
          if (TYPE_ALIGN (type) > desired_align)
            {
              if (STRICT_ALIGNMENT)
-               warning_with_decl (field, "packed attribute causes inefficient alignment for `%s'");
+               warning ("%Jpacked attribute causes inefficient alignment "
+                         "for '%D'", field, field);
              else
-               warning_with_decl (field, "packed attribute is unnecessary for `%s'");
+               warning ("%Jpacked attribute is unnecessary for '%D'",
+                        field, field);
            }
        }
       else
@@ -901,7 +903,7 @@ place_field (record_layout_info rli, tree field)
         Bump the cumulative size to multiple of field alignment.  */
 
       if (warn_padded)
-       warning_with_decl (field, "padding struct to align `%s'");
+       warning ("%Jpadding struct to align '%D'", field, field);
 
       /* If the alignment is still within offset_align, just align
         the bit position.  */
@@ -1089,6 +1091,7 @@ place_field (record_layout_info rli, tree field)
                rli->prev_field = NULL;
            }
 
+         rli->offset_align = tree_low_cst (TYPE_SIZE (type), 0);
          normalize_rli (rli);
         }
 
@@ -1310,8 +1313,6 @@ compute_record_mode (tree type)
      BLKmode only because it isn't aligned.  */
   for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
     {
-      unsigned HOST_WIDE_INT bitpos;
-
       if (TREE_CODE (field) != FIELD_DECL)
        continue;
 
@@ -1323,19 +1324,6 @@ compute_record_mode (tree type)
          || ! host_integerp (DECL_SIZE (field), 1))
        return;
 
-      bitpos = int_bit_position (field);
-
-      /* 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_low_cst (DECL_SIZE (field), 1) + bitpos - 1)
-             / BITS_PER_WORD)
-         /* But there is no problem if the field is entire words
-            or bigger than a word.  */
-         && ! (tree_low_cst (DECL_SIZE (field), 1) % BITS_PER_WORD == 0
-               || compare_tree_int (DECL_SIZE (field), BITS_PER_WORD) > 0))
-       return;
-
       /* 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.  */
@@ -1957,7 +1945,8 @@ set_sizetype (tree type)
      for the sizes in them.  */
   for (t = early_type_list; t != 0; t = TREE_CHAIN (t))
     {
-      if (TREE_CODE (TREE_VALUE (t)) != INTEGER_TYPE)
+      if (TREE_CODE (TREE_VALUE (t)) != INTEGER_TYPE
+         && TREE_CODE (TREE_VALUE (t)) != BOOLEAN_TYPE)
        abort ();
 
       TREE_TYPE (TYPE_SIZE (TREE_VALUE (t))) = bitsizetype;
@@ -1968,6 +1957,58 @@ set_sizetype (tree type)
   sizetype_set = 1;
 }
 \f
+/* TYPE is an integral type, i.e., an INTEGRAL_TYPE, ENUMERAL_TYPE,
+   BOOLEAN_TYPE, or CHAR_TYPE.  Set TYPE_MIN_VALUE and TYPE_MAX_VALUE
+   for TYPE, based on the PRECISION and whether or not the TYPE
+   IS_UNSIGNED.  PRECISION need not correspond to a width supported
+   natively by the hardware; for example, on a machine with 8-bit,
+   16-bit, and 32-bit register modes, PRECISION might be 7, 23, or
+   61.  */
+
+void
+set_min_and_max_values_for_integral_type (tree type,
+                                         int precision,
+                                         bool is_unsigned)
+{
+  tree min_value;
+  tree max_value;
+
+  if (is_unsigned)
+    {
+      min_value = build_int_2 (0, 0);
+      max_value 
+       = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
+                      ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
+                      precision - HOST_BITS_PER_WIDE_INT > 0
+                      ? ((unsigned HOST_WIDE_INT) ~0
+                         >> (HOST_BITS_PER_WIDE_INT
+                             - (precision - HOST_BITS_PER_WIDE_INT)))
+                      : 0);
+    }
+  else
+    {
+      min_value 
+       = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
+                       ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
+                      (((HOST_WIDE_INT) (-1)
+                        << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
+                            ? precision - HOST_BITS_PER_WIDE_INT - 1
+                            : 0))));    
+      max_value
+       = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
+                       ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
+                      (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
+                       ? (((HOST_WIDE_INT) 1
+                           << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
+                       : 0));
+    }
+
+  TREE_TYPE (min_value) = type;
+  TREE_TYPE (max_value) = type;
+  TYPE_MIN_VALUE (type) = min_value;
+  TYPE_MAX_VALUE (type) = max_value;
+}
+
 /* Set the extreme values of TYPE based on its precision in bits,
    then lay it out.  Used when make_signed_type won't do
    because the tree code is not INTEGER_TYPE.
@@ -1984,23 +2025,8 @@ fixup_signed_type (tree type)
   if (precision > HOST_BITS_PER_WIDE_INT * 2)
     precision = HOST_BITS_PER_WIDE_INT * 2;
 
-  TYPE_MIN_VALUE (type)
-    = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
-                   ? 0 : (HOST_WIDE_INT) (-1) << (precision - 1)),
-                  (((HOST_WIDE_INT) (-1)
-                    << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
-                        ? precision - HOST_BITS_PER_WIDE_INT - 1
-                        : 0))));
-  TYPE_MAX_VALUE (type)
-    = build_int_2 ((precision - HOST_BITS_PER_WIDE_INT > 0
-                   ? -1 : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
-                  (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
-                   ? (((HOST_WIDE_INT) 1
-                       << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
-                   : 0));
-
-  TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
-  TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
+  set_min_and_max_values_for_integral_type (type, precision, 
+                                           /*is_unsigned=*/false);
 
   /* Lay out the type: set its alignment, size, etc.  */
   layout_type (type);
@@ -2021,17 +2047,8 @@ fixup_unsigned_type (tree type)
   if (precision > HOST_BITS_PER_WIDE_INT * 2)
     precision = HOST_BITS_PER_WIDE_INT * 2;
 
-  TYPE_MIN_VALUE (type) = build_int_2 (0, 0);
-  TYPE_MAX_VALUE (type)
-    = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
-                  ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
-                  precision - HOST_BITS_PER_WIDE_INT > 0
-                  ? ((unsigned HOST_WIDE_INT) ~0
-                     >> (HOST_BITS_PER_WIDE_INT
-                         - (precision - HOST_BITS_PER_WIDE_INT)))
-                  : 0);
-  TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
-  TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
+  set_min_and_max_values_for_integral_type (type, precision, 
+                                           /*is_unsigned=*/true);
 
   /* Lay out the type: set its alignment, size, etc.  */
   layout_type (type);