This is a segfault on a degenerate bitfield case introduced by the rewrite of 
the bitfield machinery.  In Ada, we have bitfields of size zero and we ask the 
middle-end to generate accesses to them.  This doesn't work anymore because 
get_best_mode now returns VOIDmode instead of QImode in this case, which 
wreaks havoc later.

The patchlet just restores the previous behaviour.  It also makes the comment 
describing the computation of bitregion_end_ more explicit, as the original 
formulation is a bit terse on second reading, even for the reviewer. :-)

Bootstrapped/regtested on x86-64/Linux, applied on the mainline as obvious.


2012-11-30  Eric Botcazou  <ebotca...@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  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/specs/pack9.ads: New test.


-- 
Eric Botcazou
Index: stor-layout.c
===================================================================
--- stor-layout.c	(revision 193985)
+++ stor-layout.c	(working copy)
@@ -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;
     }
-- { 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;

Reply via email to