public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix segfault on degenerate bitfield case
@ 2012-11-30 23:54 Eric Botcazou
  2012-12-01  9:30 ` Richard Sandiford
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2012-11-30 23:54 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

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.


-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 991 bytes --]

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

[-- Attachment #3: pack9.ads --]
[-- Type: text/x-adasrc, Size: 251 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Fix segfault on degenerate bitfield case
  2012-11-30 23:54 Fix segfault on degenerate bitfield case Eric Botcazou
@ 2012-12-01  9:30 ` Richard Sandiford
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2012-12-01  9:30 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-01  9:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-30 23:54 Fix segfault on degenerate bitfield case Eric Botcazou
2012-12-01  9:30 ` Richard Sandiford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).