]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Don't build equivalent record aggregate if type has predicates
authorGhjuvan Lacambre <lacambre@adacore.com>
Wed, 11 Mar 2020 07:55:56 +0000 (08:55 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 10 Jun 2020 13:35:02 +0000 (09:35 -0400)
2020-06-10  Ghjuvan Lacambre  <lacambre@adacore.com>

gcc/ada/

* exp_ch3.adb (Build_Equivalent_Record_Aggregate): Return Empty
if Etype of record component has predicates.

gcc/ada/exp_ch3.adb

index 76b620197781b4c1f357f4ab02fa768339b145de..3bc1f607f9af9bd1754a8a493926602d30d97dd1 100644 (file)
@@ -1211,6 +1211,17 @@ package body Exp_Ch3 is
             then
                Initialization_Warning (T);
                return Empty;
+
+               --  We need to return empty if the type has predicates because
+               --  this would otherwise duplicate calls to the predicate
+               --  function. If the type hasn't been frozen before being
+               --  referenced in the current record, the extraneous call to
+               --  the predicate function would be inserted somewhere before
+               --  the predicate function is elaborated, which would result in
+               --  an invalid tree.
+
+            elsif Has_Predicates (Etype (Comp)) then
+               return Empty;
             end if;
 
          elsif Is_Scalar_Type (Etype (Comp)) then