From: Eric Botcazou Date: Tue, 5 Sep 2017 08:14:35 +0000 (+0000) Subject: trans.c (pos_to_constructor): Skip conversions to an unconstrained array type. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=babf697a2da6eff7ea91e02605023b309119a175;p=gcc.git trans.c (pos_to_constructor): Skip conversions to an unconstrained array type. * gcc-interface/trans.c (pos_to_constructor): Skip conversions to an unconstrained array type. From-SVN: r251691 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index fe93c05961d..32030b55e28 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2017-09-05 Eric Botcazou + + * gcc-interface/trans.c (pos_to_constructor): Skip conversions to an + unconstrained array type. + 2017-08-30 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 693c74f2a08..f7b51bbbd0a 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -9826,7 +9826,14 @@ pos_to_constructor (Node_Id gnat_expr, tree gnu_array_type, gnat_component_type); else { - gnu_expr = gnat_to_gnu (gnat_expr); + /* If the expression is a conversion to an unconstrained array type, + skip it to avoid spilling to memory. */ + if (Nkind (gnat_expr) == N_Type_Conversion + && Is_Array_Type (Etype (gnat_expr)) + && !Is_Constrained (Etype (gnat_expr))) + gnu_expr = gnat_to_gnu (Expression (gnat_expr)); + else + gnu_expr = gnat_to_gnu (gnat_expr); /* Before assigning the element to the array, make sure it is in range. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 74790654be8..28691293aa6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-09-05 Eric Botcazou + + * testsuite/gnat.dg/array29.ad[sb]: New test. + 2017-09-05 Martin Liska PR tree-optimization/82032 diff --git a/gcc/testsuite/gnat.dg/array29.adb b/gcc/testsuite/gnat.dg/array29.adb new file mode 100644 index 00000000000..9736941f3a1 --- /dev/null +++ b/gcc/testsuite/gnat.dg/array29.adb @@ -0,0 +1,26 @@ +-- { dg-do compile } +-- { dg-options "-O" } + +package body Array29 is + + procedure Copy (Src : in Matrix; Dst : out Matrix) is + begin + for I in Src'Range (1) loop + for J in Src'Range (2) loop + Dst (I, J) := Src (I, J); + end loop; + end loop; + end; + + procedure Proc is + N : constant := 2; + FM1 : constant Matrix (1 .. N, 1 .. N) := ((1.0, 2.0), (3.0, 4.0)); + FM2 : constant Matrix (1 .. N, 1 .. N) := ((1.0, 2.0), (3.0, 4.0)); + A : constant array (1 .. 2) of Matrix (1 .. N, 1 .. N) + := (Matrix (FM1), Matrix (FM2)); + Final : Matrix (1 .. N, 1 .. N); + begin + Copy (Src => A (1), Dst => Final); + end; + +end Array29; diff --git a/gcc/testsuite/gnat.dg/array29.ads b/gcc/testsuite/gnat.dg/array29.ads new file mode 100644 index 00000000000..049ca1f3c66 --- /dev/null +++ b/gcc/testsuite/gnat.dg/array29.ads @@ -0,0 +1,7 @@ +package Array29 is + + type Matrix is array (Integer range <>, Integer range <>) of Long_Float; + + procedure Proc; + +end Array29;