summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2018-11-14 11:41:41 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-11-14 11:41:41 +0000
commit41a59f6b14660aaf802d749a22d07c14660312ed (patch)
tree515b8747f3b83e3566374bc214d9b0fdcea2458e
parent1e3c434fa08b0ee0e4f9b5ce803e282d8832a559 (diff)
downloadgcc-41a59f6b14660aaf802d749a22d07c14660312ed.tar.gz
[Ada] Compiler crash on decl. with limited aggregate and address clause
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. 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. From-SVN: r266125
-rw-r--r--gcc/ada/ChangeLog10
-rw-r--r--gcc/ada/exp_ch3.adb12
-rw-r--r--gcc/ada/sem_ch3.adb8
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gnat.dg/limited_aggr.adb5
-rw-r--r--gcc/testsuite/gnat.dg/limited_aggr.ads10
6 files changed, 49 insertions, 1 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 52ea778131a..6be83416933 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,13 @@
+2018-11-14 Ed Schonberg <schonberg@adacore.com>
+
+ * 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.
+
2018-11-14 Bob Duff <duff@adacore.com>
* sem_attr.adb (To_Address): Simplify setting of
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 1eddd61b992..64cded5c0a1 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/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));
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index fae1d5dc66a..f7ba4dcadc6 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/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"
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2103f49b4e8..6c45c142312 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-14 Ed Schonberg <schonberg@adacore.com>
+
+ * gnat.dg/limited_aggr.adb, gnat.dg/limited_aggr.ads: New
+ testcase.
+
2018-11-14 Justin Squirek <squirek@adacore.com>
* gnat.dg/enum5.adb: New testcase.
diff --git a/gcc/testsuite/gnat.dg/limited_aggr.adb b/gcc/testsuite/gnat.dg/limited_aggr.adb
new file mode 100644
index 00000000000..21f84ef3f3a
--- /dev/null
+++ b/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;
diff --git a/gcc/testsuite/gnat.dg/limited_aggr.ads b/gcc/testsuite/gnat.dg/limited_aggr.ads
new file mode 100644
index 00000000000..49b7e8dc700
--- /dev/null
+++ b/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;