This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix ICE on defaulted string parameters at -O


This is a regression present on the mainline, 7 and 6 branches if optimization 
is enabled.  It turns out that we don't need to generate a VIEW_CONVERT_EXPR 
for a regular conversion between an unconstrained array parameter and one of 
its constrained subtype.

Tested on x86_64-suse-linux, applied on the mainline, 7 and 6 branches.


2017-11-10  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/utils.c (convert) <RECORD_TYPE>: Add comment and do
	not fall through to the next case.
	<ARRAY_TYPE>: Deal specially with a dereference from another array
	type with the same element type.


2017-11-10  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt69.adb: New test.

-- 
Eric Botcazou
Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 254599)
+++ gcc-interface/utils.c	(working copy)
@@ -4706,6 +4706,7 @@ convert (tree type, tree expr)
       return fold (convert_to_real (type, expr));
 
     case RECORD_TYPE:
+      /* Do a normal conversion between scalar and justified modular type.  */
       if (TYPE_JUSTIFIED_MODULAR_P (type) && !AGGREGATE_TYPE_P (etype))
 	{
 	  vec<constructor_elt, va_gc> *v;
@@ -4717,9 +4718,27 @@ convert (tree type, tree expr)
 	  return gnat_build_constructor (type, v);
 	}
 
-      /* ... fall through ... */
+      /* In these cases, assume the front-end has validated the conversion.
+	 If the conversion is valid, it will be a bit-wise conversion, so
+	 it can be viewed as an unchecked conversion.  */
+      return unchecked_convert (type, expr, false);
 
     case ARRAY_TYPE:
+      /* Do a normal conversion between unconstrained and constrained array
+	 type, assuming the latter is a constrained version of the former.  */
+      if (TREE_CODE (expr) == INDIRECT_REF
+	  && ecode == ARRAY_TYPE
+	  && TREE_TYPE (etype) == TREE_TYPE (type))
+	{
+	  tree ptr_type = build_pointer_type (type);
+	  tree t = build_unary_op (INDIRECT_REF, NULL_TREE,
+				   fold_convert (ptr_type,
+						 TREE_OPERAND (expr, 0)));
+	  TREE_READONLY (t) = TREE_READONLY (expr);
+	  TREE_THIS_NOTRAP (t) = TREE_THIS_NOTRAP (expr);
+	  return t;
+	}
+
       /* In these cases, assume the front-end has validated the conversion.
 	 If the conversion is valid, it will be a bit-wise conversion, so
 	 it can be viewed as an unchecked conversion.  */
-- { dg-do compile }
-- { dg-options "-O" }

with Ada.Text_IO;

procedure Opt69 is

   procedure Inner
     (A : String := (1 .. 15 => ASCII.NUL);
      B : String := (1 .. 5 => ASCII.NUL);
      C : String := (1 .. 5 => ASCII.NUL))
   is
      Aa : String (1 .. 15);
      Bb : String (1 .. 5);
      Cc : String (1 .. 5);
   begin
      Aa := A;
      Bb := B;
      Cc := C;

      Ada.Text_IO.Put_Line (Aa);
      Ada.Text_IO.Put_Line (Bb);
      Ada.Text_IO.Put_Line (Cc);
   end;

begin
   Inner;
end;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]