stor-layout.c (bit_field_mode_iterator::bit_field_mode_iterator): Deal with degenerat...
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 30 Nov 2012 22:36:07 +0000 (22:36 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 30 Nov 2012 22:36:07 +0000 (22:36 +0000)
* stor-layout.c (bit_field_mode_iterator::bit_field_mode_iterator): Deal
with degenerate cases where the bitsize isn't positive.  Rework comment.

From-SVN: r194009

gcc/ChangeLog
gcc/stor-layout.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/specs/pack9.ads [new file with mode: 0644]

index c80c41a8a6fcf0ced8890f18f9b1f0ff9259a30b..356bb36bce21de6dd54eb86acce66f8522391af3 100644 (file)
@@ -1,3 +1,8 @@
+2012-11-30  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * stor-layout.c (bit_field_mode_iterator::bit_field_mode_iterator): Deal
+       with degenerate cases where the bitsize isn't positive.  Rework comment.
+
 2012-11-30  David Edelsohn  <dje.gcc@gmail.com>
 
        * xcoffout.c (xcoff_tls_data_section_name): Define.
index 3d97796da5c8e5b082adb4fb4d833d06a63b2e82..4227694a4be8a9e1fd3e6a9cfa905cc4f1271b62 100644 (file)
@@ -2648,10 +2648,14 @@ bit_field_mode_iterator
 {
   if (!bitregion_end_)
     {
-      /* We can assume that any aligned chunk of UNITS bits that overlaps
-        the bitfield is mapped and won't trap.  */
-      unsigned HOST_WIDE_INT units = MIN (align, MAX (BIGGEST_ALIGNMENT,
-                                                     BITS_PER_WORD));
+      /* We can assume that any aligned chunk of ALIGN bits that overlaps
+        the bitfield is mapped and won't trap, provided that ALIGN isn't
+        too large.  The cap is the biggest required alignment for data,
+        or at least the word size.  And force one such chunk at least.  */
+      unsigned HOST_WIDE_INT units
+       = MIN (align, MAX (BIGGEST_ALIGNMENT, BITS_PER_WORD));
+      if (bitsize <= 0)
+       bitsize = 1;
       bitregion_end_ = bitpos + bitsize + units - 1;
       bitregion_end_ -= bitregion_end_ % units + 1;
     }
index 6bfa0933eefdda9b2d352f428532a6704216a8c3..573e3906357e7506ca70133477b674fcd42978bf 100644 (file)
@@ -1,3 +1,7 @@
+2012-11-30  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/specs/pack9.ads: New test.
+
 2012-11-30  Martin Jambor  <mjambor@suse.cz>
 
        PR middle-end/52890
diff --git a/gcc/testsuite/gnat.dg/specs/pack9.ads b/gcc/testsuite/gnat.dg/specs/pack9.ads
new file mode 100644 (file)
index 0000000..9d5e027
--- /dev/null
@@ -0,0 +1,15 @@
+-- { dg-do compile }
+
+package Pack9 is
+
+  subtype Zero is Natural range 0 .. 0;
+
+  type Rec (D : Boolean) is record
+    case D is
+       when True => Z : Zero;
+       when False => null;
+    end case;
+  end record;
+  pragma Pack (Rec);
+    
+end Pack9;