re PR c++/10549 (ICE in store_bit_field on bitfields that exceed the precision of...
authorMark Mitchell <mark@codesourcery.com>
Tue, 29 Apr 2003 21:28:41 +0000 (21:28 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Tue, 29 Apr 2003 21:28:41 +0000 (21:28 +0000)
PR c++/10549
* class.c (layout_class_type): Mark overlong bitfields as having
the maximum size permitted by their type, after layout.

PR c++/10549
* g++.dg/other/bitfield1.C: New test.

From-SVN: r66257

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/bitfield1.C [new file with mode: 0644]

index 3a65705a2898e1392c19b0059e1514ebac72554f..3da06762f4bffef19a4010333e02e3fc8b48df5a 100644 (file)
@@ -1,5 +1,9 @@
 2003-04-29  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/10549
+       * class.c (layout_class_type): Mark overlong bitfields as having
+       the maximum size permitted by their type, after layout.
+
        PR c++/10527
        * error.c (dump_expr): Correctly handling of NEW_EXPR.4
 
index 33ece0dbe2fc22f44bdc542332e727630a891d3a..7dbfa768edd8bbf45e1dc8ede8dfdb84c534d03d 100644 (file)
@@ -4724,7 +4724,6 @@ layout_class_type (tree t, tree *virtuals_p)
     {
       tree type;
       tree padding;
-      bool was_unnamed_p = false;
 
       /* We still pass things that aren't non-static data members to
         the back-end, in case it wants to do something with them.  */
@@ -4758,6 +4757,7 @@ layout_class_type (tree t, tree *virtuals_p)
        {
          integer_type_kind itk;
          tree integer_type;
+         bool was_unnamed_p = false;
          /* We must allocate the bits as if suitably aligned for the
             longest integer type that fits in this many bits.  type
             of the field.  Then, we are supposed to use the left over
@@ -4809,14 +4809,18 @@ layout_class_type (tree t, tree *virtuals_p)
          DECL_SIZE (field) = TYPE_SIZE (integer_type);
          DECL_ALIGN (field) = TYPE_ALIGN (integer_type);
          DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (integer_type);
+         layout_nonempty_base_or_field (rli, field, NULL_TREE,
+                                        empty_base_offsets);
+         if (was_unnamed_p)
+           DECL_NAME (field) = NULL_TREE;
+         /* Now that layout has been performed, set the size of the
+            field to the size of its declared type; the rest of the
+            field is effectively invisible.  */
+         DECL_SIZE (field) = TYPE_SIZE (type);
        }
-
-      layout_nonempty_base_or_field (rli, field, NULL_TREE,
-                                    empty_base_offsets);
-      /* If the bit-field had no name originally, remove the name
-        now.  */
-      if (was_unnamed_p)
-       DECL_NAME (field) = NULL_TREE;
+      else
+       layout_nonempty_base_or_field (rli, field, NULL_TREE,
+                                      empty_base_offsets);
 
       /* Remember the location of any empty classes in FIELD.  */
       if (abi_version_at_least (2))
index 0a670f8797a4c6b768aac48d1c9495b38eb29b66..9fba7a37219f7d4c68d506bfa6b5814f29fe9ff7 100644 (file)
@@ -1,5 +1,8 @@
 2003-04-29  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/10549
+       * g++.dg/other/bitfield1.C: New test.
+
        PR c++/10527
        * g++.dg/init/new7.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/other/bitfield1.C b/gcc/testsuite/g++.dg/other/bitfield1.C
new file mode 100644 (file)
index 0000000..896490f
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-options "-w" }
+
+union u1 {
+  char m1 : 16;
+} x;
+
+int main () {
+  x.m1 = 256;
+}