From patchwork Fri Nov 30 22:32:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Fix segfault on degenerate bitfield case Date: Fri, 30 Nov 2012 12:32:15 -0000 From: Eric Botcazou X-Patchwork-Id: 203065 Message-Id: <2334390.fbpLepaxAm@polaris> To: gcc-patches@gcc.gnu.org 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 * 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 * gnat.dg/specs/pack9.ads: New test. 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; }