aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorHristian Kirtchev <kirtchev@adacore.com>2018-05-22 13:26:55 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-05-22 13:26:55 +0000
commit02db8169939bb489abb6c7025395a3fc671b79b6 (patch)
treecbfa4d2c52a3d0d3df46656e51a945aa39790347 /gcc/ada
parent9820b3897803c38f66f8515dc15cdb3e10c7ad20 (diff)
downloadgcc-02db8169939bb489abb6c7025395a3fc671b79b6.zip
gcc-02db8169939bb489abb6c7025395a3fc671b79b6.tar.gz
gcc-02db8169939bb489abb6c7025395a3fc671b79b6.tar.bz2
[Ada] Crash on partial initialization of controlled component
This patch modifies the late expansion of record aggregates to ensure that the generated code which handles a controlled component initialized by a function call is inserted in line with the rest of the initialization code, rather than before the record aggregate. This way the function call has proper access to the discriminants of the object being created. 2018-05-22 Hristian Kirtchev <kirtchev@adacore.com> gcc/ada/ * exp_aggr.adb (Initialize_Ctrl_Record_Component): Insert the generated code for a transient component in line with the rest of the initialization code, rather than before the aggregate. This ensures that the component has proper visibility of the discriminants. gcc/testsuite/ * gnat.dg/controlled8.adb: New testcase. From-SVN: r260532
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog7
-rw-r--r--gcc/ada/exp_aggr.adb10
2 files changed, 14 insertions, 3 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 3805c22..effa964 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-22 Hristian Kirtchev <kirtchev@adacore.com>
+
+ * exp_aggr.adb (Initialize_Ctrl_Record_Component): Insert the generated
+ code for a transient component in line with the rest of the
+ initialization code, rather than before the aggregate. This ensures
+ that the component has proper visibility of the discriminants.
+
2018-05-22 Jerome Lambourg <lambourg@adacore.com>
* adaint.c: Reorganize QNX-specific macros, use syspage to retreive the
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 975d32f..356686e 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -2846,7 +2846,7 @@ package body Exp_Aggr is
In_Place_Expansion :=
Nkind (Init_Expr) = N_Function_Call
- and then not Is_Build_In_Place_Result_Type (Comp_Typ);
+ and then not Is_Build_In_Place_Result_Type (Comp_Typ);
-- The initialization expression is a controlled function call.
-- Perform in-place removal of side effects to avoid creating a
@@ -2865,7 +2865,11 @@ package body Exp_Aggr is
Set_No_Side_Effect_Removal (Init_Expr);
-- Install all hook-related declarations and prepare the clean up
- -- statements.
+ -- statements. The generated code follows the initialization order
+ -- of individual components and discriminants, rather than being
+ -- inserted prior to the aggregate. This ensures that a transient
+ -- component which mentions a discriminant has proper visibility
+ -- of the discriminant.
Process_Transient_Component
(Loc => Loc,
@@ -2873,7 +2877,7 @@ package body Exp_Aggr is
Init_Expr => Init_Expr,
Fin_Call => Fin_Call,
Hook_Clear => Hook_Clear,
- Aggr => N);
+ Stmts => Stmts);
end if;
-- Use the noncontrolled component initialization circuitry to