From: Steve Baird <ba...@adacore.com>

In some cases involving assigning an aggregate to a formal parameter of
an unconstrained discriminated subtype that has a Dynamic_Predicate, and where
the discriminated type also has a component of an unconstrained discriminated
subtype, the front end generates a malformed tree which causes a compilation
failure when the backend fails a consistency check.

gcc/ada/ChangeLog:

        * exp_aggr.adb (Convert_To_Assignments): Add calls to Ensure_Defined
        before generating assignments to components that could be
        associated with a not-yet-defined itype.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_aggr.adb | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 9458bdea663..cd98369a918 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -4349,6 +4349,7 @@ package body Exp_Aggr is
         and then Is_Limited_Type (Typ)
       then
          Target_Expr := New_Copy_Tree (Name (Parent_Node));
+         Ensure_Defined (Typ, Parent_Node);
          Insert_Actions (Parent_Node,
            Build_Record_Aggr_Code (N, Typ, Target_Expr));
          Rewrite (Parent_Node, Make_Null_Statement (Loc));
@@ -4374,6 +4375,7 @@ package body Exp_Aggr is
 
             if Nkind (N) in N_Aggregate | N_Extension_Aggregate then
                Target_Expr := New_Copy_Tree (Lhs);
+               Ensure_Defined (Typ, Parent_Node);
                Insert_Actions (Parent_Node,
                  Build_Record_Aggr_Code (N, Typ, Target_Expr));
                Rewrite (Parent_Node, Make_Null_Statement (Loc));
-- 
2.43.0

Reply via email to