diff mbox

Fix segfault on degenerate bitfield case

Message ID 2334390.fbpLepaxAm@polaris
State New
Headers show

Commit Message

Eric Botcazou Nov. 30, 2012, 10:32 p.m. UTC
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  <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  Eric Botcazou  <ebotcazou@adacore.com>

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

Comments

Richard Sandiford Dec. 1, 2012, 9:30 a.m. UTC | #1
Eric Botcazou <ebotcazou@adacore.com> writes:
> 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.

Thanks!

Richard
diff mbox

Patch

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;
     }