OSDN Git Service

* dwarf2out.c (dwarf2out_add_library_unit_info): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / stor-layout.c
index cb57cb3..caf176f 100644 (file)
@@ -1,6 +1,7 @@
 /* C-compiler utilities for types and variables storage layout
    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1996, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -338,17 +339,22 @@ layout_decl (tree decl, unsigned int known_align)
     /* For fields, it's a bit more complicated...  */
     {
       bool old_user_align = DECL_USER_ALIGN (decl);
+      bool zero_bitfield = false;
+      bool packed_p = DECL_PACKED (decl);
+      unsigned int mfa;
 
       if (DECL_BIT_FIELD (decl))
        {
          DECL_BIT_FIELD_TYPE (decl) = type;
 
          /* A zero-length bit-field affects the alignment of the next
-            field.  */
+            field.  In essence such bit-fields are not influenced by
+            any packing due to #pragma pack or attribute packed.  */
          if (integer_zerop (DECL_SIZE (decl))
-             && ! DECL_PACKED (decl)
              && ! targetm.ms_bitfield_layout_p (DECL_FIELD_CONTEXT (decl)))
            {
+             zero_bitfield = true;
+             packed_p = false;
 #ifdef PCC_BITFIELD_TYPE_MATTERS
              if (PCC_BITFIELD_TYPE_MATTERS)
                do_type_align (type, decl);
@@ -392,7 +398,7 @@ layout_decl (tree decl, unsigned int known_align)
              && DECL_ALIGN (decl) >= TYPE_ALIGN (type))
            DECL_BIT_FIELD (decl) = 0;
        }
-      else if (DECL_PACKED (decl) && DECL_USER_ALIGN (decl))
+      else if (packed_p && DECL_USER_ALIGN (decl))
        /* Don't touch DECL_ALIGN.  For other packed fields, go ahead and
           round up; we'll reduce it again below.  We want packing to
           supersede USER_ALIGN inherited from the type, but defer to
@@ -407,14 +413,14 @@ layout_decl (tree decl, unsigned int known_align)
 
         Note that do_type_align may set DECL_USER_ALIGN, so we need to
         check old_user_align instead.  */
-      if (DECL_PACKED (decl)
+      if (packed_p
          && !old_user_align
          && (DECL_NONADDRESSABLE_P (decl)
              || DECL_SIZE_UNIT (decl) == 0
              || TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST))
        DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
 
-      if (! DECL_USER_ALIGN (decl) && ! DECL_PACKED (decl))
+      if (! packed_p && ! DECL_USER_ALIGN (decl))
        {
          /* Some targets (i.e. i386, VMS) limit struct field alignment
             to a lower boundary than alignment of variables unless
@@ -428,9 +434,13 @@ layout_decl (tree decl, unsigned int known_align)
 #endif
        }
 
+      if (zero_bitfield)
+        mfa = initial_max_fld_align * BITS_PER_UNIT;
+      else
+       mfa = maximum_field_alignment;
       /* Should this be controlled by DECL_USER_ALIGN, too?  */
-      if (maximum_field_alignment != 0)
-       DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
+      if (mfa != 0)
+       DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), mfa);
     }
 
   /* Evaluate nonconstant size only once, either now or as soon as safe.  */
@@ -714,7 +724,16 @@ update_alignment_for_field (record_layout_info rli, tree field,
            type_align = ADJUST_FIELD_ALIGN (field, type_align);
 #endif
 
-         if (maximum_field_alignment != 0)
+         /* Targets might chose to handle unnamed and hence possibly
+            zero-width bitfield.  Those are not influenced by #pragmas
+            or packed attributes.  */
+         if (integer_zerop (DECL_SIZE (field)))
+           {
+             if (initial_max_fld_align)
+               type_align = MIN (type_align,
+                                 initial_max_fld_align * BITS_PER_UNIT);
+           }
+         else if (maximum_field_alignment != 0)
            type_align = MIN (type_align, maximum_field_alignment);
          else if (DECL_PACKED (field))
            type_align = MIN (type_align, BITS_PER_UNIT);
@@ -1176,6 +1195,10 @@ place_field (record_layout_info rli, tree field)
   if (DECL_BIT_FIELD_TYPE (field))
     {
       unsigned int type_align = TYPE_ALIGN (type);
+      unsigned int mfa = maximum_field_alignment;
+
+      if (integer_zerop (DECL_SIZE (field)))
+        mfa = initial_max_fld_align * BITS_PER_UNIT;
 
       /* Only the MS bitfields use this.  We used to also put any kind of
         packed bit fields into prev_field, but that makes no sense, because
@@ -1184,8 +1207,8 @@ place_field (record_layout_info rli, tree field)
         are also not fulfilled.
         There is no sane value to set rli->remaining_in_alignment to when
         a packed bitfield in prev_field is unaligned.  */
-      if (maximum_field_alignment != 0)
-       type_align = MIN (type_align, maximum_field_alignment);
+      if (mfa != 0)
+       type_align = MIN (type_align, mfa);
       gcc_assert (rli->prev_field
                  || actual_align >= type_align || DECL_PACKED (field)
                  || integer_zerop (DECL_SIZE (field))
@@ -1592,7 +1615,6 @@ layout_type (tree type)
 
     case INTEGER_TYPE:
     case ENUMERAL_TYPE:
-    case CHAR_TYPE:
       if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
          && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
        TYPE_UNSIGNED (type) = 1;
@@ -1996,10 +2018,29 @@ set_sizetype (tree type)
       ssizetype = sizetype;
       sbitsizetype = bitsizetype;
     }
+
+  /* If SIZETYPE is unsigned, we need to fix TYPE_MAX_VALUE so that
+     it is sign extended in a way consistent with force_fit_type.  */
+  if (TYPE_UNSIGNED (type))
+    {
+      tree orig_max, new_max;
+
+      orig_max = TYPE_MAX_VALUE (sizetype);
+
+      /* Build a new node with the same values, but a different type.  */
+      new_max = build_int_cst_wide (sizetype,
+                                   TREE_INT_CST_LOW (orig_max),
+                                   TREE_INT_CST_HIGH (orig_max));
+
+      /* Now sign extend it using force_fit_type to ensure
+        consistency.  */
+      new_max = force_fit_type (new_max, 0, 0, 0);
+      TYPE_MAX_VALUE (sizetype) = new_max;
+    }
 }
 \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
+/* TYPE is an integral type, i.e., an INTEGRAL_TYPE, ENUMERAL_TYPE
+   or BOOLEAN_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,