public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix segfault on double record extension
@ 2016-03-27 13:02 Eric Botcazou
  2016-04-02  8:57 ` Eric Botcazou
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2016-03-27 13:02 UTC (permalink / raw)
  To: gcc-patches

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

This is a regression present on the mainline and 5 branch, for a double record 
extension involving a size clause on the root type and a discriminant with 
variant part on the first extension...

Tested on x86_64-suse-linux, applied on the mainline and 5 branch.


2016-03-27  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (components_to_record): Add special case for     
	single field with representation clause at offset 0.


2016-03-27  Eric Botcazou  <ebotcazou@adacore.com>

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


-- 
Eric Botcazou

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

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 234493)
+++ gcc-interface/decl.c	(working copy)
@@ -7606,6 +7606,23 @@ components_to_record (tree gnu_record_ty
   if (p_gnu_rep_list && gnu_rep_list)
     *p_gnu_rep_list = chainon (*p_gnu_rep_list, gnu_rep_list);
 
+  /* If only one field has a rep clause and it starts at 0, put back the field
+     at the head of the regular field list.  This will avoid creating a useless
+     REP part below and deal with the annoying case of an extension of a record
+     with variable size and rep clause, for which the _Parent field is forced
+     at offset 0 and has variable size, which we do not support below.  */
+  else if (gnu_rep_list
+	   && !DECL_CHAIN (gnu_rep_list)
+	   && !variants_have_rep
+	   && first_free_pos
+	   && integer_zerop (first_free_pos)
+	   && integer_zerop (bit_position (gnu_rep_list)))
+    {
+      DECL_CHAIN (gnu_rep_list) = gnu_field_list;
+      gnu_field_list = gnu_rep_list;
+      gnu_rep_list = NULL_TREE;
+    }
+
   /* Otherwise, sort the fields by bit position and put them into their own
      record, before the others, if we also have fields without rep clause.  */
   else if (gnu_rep_list)

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

-- { dg-do compile }

package Double_Record_Extension3 is

   type Rec1 is tagged record
      Id : Integer;
   end record;

   for Rec1 use record
      Id at 8 range 0 .. 31;
   end record;

   type Rec2 (Size : Integer) is new Rec1 with record
      Data : String (1 .. Size);
   end record;

   type Rec3 is new Rec2 (Size => 128) with record
      Valid : Boolean;
   end record;

end Double_Record_Extension3;


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

* Re: [Ada] Fix segfault on double record extension
  2016-03-27 13:02 [Ada] Fix segfault on double record extension Eric Botcazou
@ 2016-04-02  8:57 ` Eric Botcazou
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Botcazou @ 2016-04-02  8:57 UTC (permalink / raw)
  To: gcc-patches

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

> This is a regression present on the mainline and 5 branch, for a double
> record extension involving a size clause on the root type and a
> discriminant with variant part on the first extension...
> 
> Tested on x86_64-suse-linux, applied on the mainline and 5 branch.
> 
> 
> 2016-03-27  Eric Botcazou  <ebotcazou@adacore.com>
> 
> 	* gcc-interface/decl.c (components_to_record): Add special case for
> 	single field with representation clause at offset 0.

The attached patch restricts the change to the problematic cases.

Tested on x86_64-suse-linux, applied on the mainline and 5 branch.


	* gcc-interface/decl.c (components_to_record): Restrict the previous
	change to fields with variable size.

-- 
Eric Botcazou

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

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 234695)
+++ gcc-interface/decl.c	(working copy)
@@ -7606,13 +7606,15 @@ components_to_record (tree gnu_record_ty
   if (p_gnu_rep_list && gnu_rep_list)
     *p_gnu_rep_list = chainon (*p_gnu_rep_list, gnu_rep_list);
 
-  /* If only one field has a rep clause and it starts at 0, put back the field
-     at the head of the regular field list.  This will avoid creating a useless
-     REP part below and deal with the annoying case of an extension of a record
-     with variable size and rep clause, for which the _Parent field is forced
-     at offset 0 and has variable size, which we do not support below.  */
+  /* Deal with the annoying case of an extension of a record with variable size
+     and partial rep clause, for which the _Parent field is forced at offset 0
+     and has variable size, which we do not support below.  Note that we cannot
+     do it if the field has fixed size because we rely on the presence of the
+     REP part built below to trigger the reordering of the fields in a derived
+     record type when all the fields have a fixed position.  */
   else if (gnu_rep_list
 	   && !DECL_CHAIN (gnu_rep_list)
+	   && TREE_CODE (DECL_SIZE (gnu_rep_list)) != INTEGER_CST
 	   && !variants_have_rep
 	   && first_free_pos
 	   && integer_zerop (first_free_pos)

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

end of thread, other threads:[~2016-04-02  8:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-27 13:02 [Ada] Fix segfault on double record extension Eric Botcazou
2016-04-02  8:57 ` Eric Botcazou

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).