public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Fix ICE on multi-dimensional array
Date: Tue, 05 Sep 2017 08:22:00 -0000	[thread overview]
Message-ID: <8455722.vByhrAPZx7@polaris> (raw)

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

This is a regression present on the mainline, 7 and 6 branches, in the form of 
an ICE during tree-sra, which is confused by an unconstrained array type.

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


2017-09-05  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/trans.c (pos_to_constructor): Skip conversions to an
	unconstrained array type.


2017-09-05  Eric Botcazou  <ebotcazou@adacore.com>

	* testsuite/gnat.dg/array29.ad[sb]: New test.

-- 
Eric Botcazou

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

Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c	(revision 251553)
+++ gcc-interface/trans.c	(working copy)
@@ -9826,7 +9826,14 @@ pos_to_constructor (Node_Id gnat_expr, t
 				       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.  */

[-- Attachment #3: array29.adb --]
[-- Type: text/x-adasrc, Size: 662 bytes --]

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

[-- Attachment #4: array29.ads --]
[-- Type: text/x-adasrc, Size: 128 bytes --]

package Array29 is

  type Matrix is array (Integer range <>, Integer range <>) of Long_Float;

  procedure Proc;

end Array29;

                 reply	other threads:[~2017-09-05  8:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8455722.vByhrAPZx7@polaris \
    --to=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).