public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Ed Schonberg <schonberg@adacore.com>
Subject: [Ada] Compiler crash on decl. with limited aggregate and address clause
Date: Wed, 14 Nov 2018 11:45:00 -0000	[thread overview]
Message-ID: <20181114114433.GA74094@adacore.com> (raw)

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

This patch fixes a compiler abort on an object declaration whose
expression is an aggregate, when the type of the object is limited and
the declaration is followed by an address clause for the declared
object.

Tested on x86_64-pc-linux-gnu, committed on trunk

2018-11-14  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* exp_ch3.adb: (Expand_N_Object_Declaration): If the expression
	is a limited aggregate its resolution is delayed until the
	object declaration is expanded.
	* sem_ch3.adb: (Analyze_Object_Declaration): If the expression
	is a limited aggregate and the declaration has a following
	address clause indicate that resolution of the aggregate (which
	must be built in place) must be delayed.

gcc/testsuite/

	* gnat.dg/limited_aggr.adb, gnat.dg/limited_aggr.ads: New
	testcase.

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

--- gcc/ada/exp_ch3.adb
+++ gcc/ada/exp_ch3.adb
@@ -6586,6 +6586,16 @@ package body Exp_Ch3 is
          --  thus avoid creating a temporary.
 
          if Is_Delayed_Aggregate (Expr_Q) then
+
+            --  An aggregate that must be built in place is not resolved
+            --  and expanded until the enclosing construct is expanded.
+            --  This will happen when the aggregqte is limited and the
+            --  declared object has a following address clause.
+
+            if Is_Limited_Type (Typ) and then not Analyzed (Expr) then
+               Resolve (Expr, Typ);
+            end if;
+
             Convert_Aggr_In_Object_Decl (N);
 
          --  Ada 2005 (AI-318-02): If the initialization expression is a call
@@ -7022,7 +7032,7 @@ package body Exp_Ch3 is
                --  Given that the type is limited we cannot perform a copy. If
                --  Expr_Q is the reference to a variable we mark the variable
                --  as OK_To_Rename to expand this declaration into a renaming
-               --  declaration (see bellow).
+               --  declaration (see below).
 
                if Is_Entity_Name (Expr_Q) then
                   Set_OK_To_Rename (Entity (Expr_Q));

--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -4283,6 +4283,14 @@ package body Sem_Ch3 is
          then
             Set_Etype (E, T);
 
+            --  If the aggregate is limited it will be built in place,
+            --  and its expansion is deferred until the object declaration
+            --  is expanded.
+
+            if Is_Limited_Type (T) then
+               Set_Expansion_Delayed (E);
+            end if;
+
          else
 
             --  If the expression is a formal that is a "subprogram pointer"

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/limited_aggr.adb
@@ -0,0 +1,5 @@
+--  { dg-do compile }
+
+package body Limited_Aggr is
+   procedure Dummy is null;
+end Limited_Aggr;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/limited_aggr.ads
@@ -0,0 +1,10 @@
+package Limited_Aggr is
+   type R is limited record
+      F1, F2 : Integer;
+   end record;
+   X : array (1..2) of integer;
+   Y : R := (-111, -222);
+   for Y'Address use X'Address;
+
+   procedure Dummy;
+end Limited_Aggr;


                 reply	other threads:[~2018-11-14 11:44 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=20181114114433.GA74094@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=schonberg@adacore.com \
    /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).