[Ada] Don't build equivalent record aggregate if type has predicates

Message ID 20200610133540.GA80793@adacore.com
State New
Headers show
Series
  • [Ada] Don't build equivalent record aggregate if type has predicates
Related show

Commit Message

Pierre-Marie de Rodat June 10, 2020, 1:35 p.m.
Building equivalent record aggregates when the type of the aggregate has
predicate functions can result in Gigi crashes if the type hasn't been
frozen yet. Since Build_Equivalent_Record_Aggregate is an optimization,
it's ok to disable it when encountering aggregates with predicates.

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

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.

Patch

--- gcc/ada/exp_ch3.adb
+++ gcc/ada/exp_ch3.adb
@@ -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