In Resolve_Array_Aggregate we typically compute and set Aggregate_Bounds
based on the aggregate itself. We only need to keep the already computed
bounds for aggregates that have been optimized into positional ones.

However, we kept the already computed bounds for other aggregates too.
In particular, we also kept bounds computed by
Preanalyze_Assert_Expression for consequents of Contract_Cases. This was
wrong, because those bounds could reference 'Old that we intended to be
rewritten by Expand_Attributes_In_Consequence.

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

gcc/ada/

        * sem_aggr.adb (Resolve_Array_Aggregate): Only keep the bounds
        for internally generated attributes; otherwise, compute them
                anew.
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -2800,7 +2800,10 @@ package body Sem_Aggr is
       --  Exp_Aggr.Convert_To_Positional, so we don't want to change those
       --  bounds.
 
-      if Present (Aggregate_Bounds (N)) and then not Others_Allowed then
+      if Present (Aggregate_Bounds (N))
+        and then not Others_Allowed
+        and then not Comes_From_Source (N)
+      then
          Aggr_Low  := Low_Bound  (Aggregate_Bounds (N));
          Aggr_High := High_Bound (Aggregate_Bounds (N));
       end if;


Reply via email to