public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Get rid of questionable VIEW_CONVERT_EXPR generated by convert
@ 2009-10-17 11:20 Eric Botcazou
  2009-10-17 16:40 ` Eric Botcazou
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2009-10-17 11:20 UTC (permalink / raw)
  To: gcc-patches

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

The new SRA appears to be less forgiving and aborts on the attached testcase.
The problem pertains to an assignment with a VIEW_CONVERT_EXPR between a 
8-byte record (src) and a 16-byte record (dest) on the RHS, which is barely 
legal.

Such a VCE is generated by convert for the conversion from a small constrained 
discriminated record subtype to a padded version of its discriminated record 
type, when the latter has self-referential size.  The attached patch intructs 
it to pad up to the size of the dest before building the VIEW_CONVERT_EXPR.

Tested on i586-suse-linux, applied on the mainline.


2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/utils.c (convert): When converting to a padded type
	with an inner type of self-referential size, pad the expression before
	doing the unchecked conversion.


2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/aggr11.adb: New test.
	* gnat.dg/aggr11_pkg.ads: New helper.


-- 
Eric Botcazou

[-- Attachment #2: aggr11.adb --]
[-- Type: text/x-adasrc, Size: 405 bytes --]

-- { dg-do compile }
-- { dg-options "-O" }

with Aggr11_Pkg; use Aggr11_Pkg;

procedure Aggr11 is

  A : Arr := ((1 => (Kind  => No_Error, B => True),
               2 => (Kind => Error),
               3 => (Kind => Error),
               4 => (Kind  => No_Error, B => True),
               5 => (Kind  => No_Error, B => True),
               6 => (Kind  => No_Error, B => True)));

begin
   null;
end;

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

package Aggr11_Pkg is

   type Error_Type is (No_Error, Error);

   type Rec (Kind : Error_Type := No_Error) is record
     case Kind is
       when Error => null;
       when others => B : Boolean;
     end case;
   end record;

   type Arr is array (1..6) of Rec;

end Aggr11_Pkg;

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

* Re: [Ada] Get rid of questionable VIEW_CONVERT_EXPR generated by convert
  2009-10-17 11:20 [Ada] Get rid of questionable VIEW_CONVERT_EXPR generated by convert Eric Botcazou
@ 2009-10-17 16:40 ` Eric Botcazou
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Botcazou @ 2009-10-17 16:40 UTC (permalink / raw)
  To: gcc-patches

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

> 2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>
>
> 	* gcc-interface/utils.c (convert): When converting to a padded type
> 	with an inner type of self-referential size, pad the expression before
> 	doing the unchecked conversion.

Patch attached this time.

-- 
Eric Botcazou

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

Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 154390)
+++ gcc-interface/utils.c	(working copy)
@@ -3861,12 +3861,17 @@ convert (tree type, tree expr)
 		     == TYPE_NAME (TREE_TYPE (TYPE_FIELDS (type))))))
 	return convert (type, TREE_OPERAND (expr, 0));
 
-      /* If the result type is a padded type with a self-referentially-sized
-	 field and the expression type is a record, do this as an unchecked
-	 conversion.  */
+      /* If the inner type is of self-referential size and the expression type
+	 is a record, do this as an unchecked conversion.  But first pad the
+	 expression if possible to have the same size on both sides.  */
       if (TREE_CODE (etype) == RECORD_TYPE
 	  && CONTAINS_PLACEHOLDER_P (DECL_SIZE (TYPE_FIELDS (type))))
-	return unchecked_convert (type, expr, false);
+	{
+	  if (TREE_CONSTANT (TYPE_SIZE (etype)))
+	    expr = convert (maybe_pad_type (etype, TYPE_SIZE (type), 0, Empty,
+			    false, false, false, true), expr);
+	  return unchecked_convert (type, expr, false);
+	}
 
       /* If we are converting between array types with variable size, do the
 	 final conversion as an unchecked conversion, again to avoid the need

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

end of thread, other threads:[~2009-10-17 16:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-17 11:20 [Ada] Get rid of questionable VIEW_CONVERT_EXPR generated by convert Eric Botcazou
2009-10-17 16:40 ` 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).