]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix internal error on declare-expression in post-condition
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 10 Mar 2023 17:05:13 +0000 (18:05 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Wed, 27 Sep 2023 08:16:25 +0000 (10:16 +0200)
It comes from an incorrect node sharing in the expanded tree.

gcc/ada/

* sem_ch3.adb (Find_Type_Of_Object): Copy the object definition when
building the subtype declaration in the case of a spec expression.

gcc/ada/sem_ch3.adb

index e462fa9bf1bb67ca1e0aa2f944502778d07c33b2..2e9f8aace1a5a0d9bee787a14aef9b318aaac9f6 100644 (file)
@@ -18425,19 +18425,21 @@ package body Sem_Ch3 is
             Analyze (Subtype_Mark (Obj_Def));
 
             declare
-               Base_T : constant Entity_Id := Entity (Subtype_Mark (Obj_Def));
-               Decl   : constant Node_Id :=
+               Base_T  : constant Entity_Id := Entity (Subtype_Mark (Obj_Def));
+               New_Def : constant Node_Id   := New_Copy_Tree (Obj_Def);
+               Decl    : constant Node_Id   :=
                  Make_Subtype_Declaration (Sloc (P),
                    Defining_Identifier => T,
-                   Subtype_Indication  => Relocate_Node (Obj_Def));
+                   Subtype_Indication  => New_Def);
+
             begin
                Set_Etype  (T, Base_T);
                Mutate_Ekind  (T, Subtype_Kind (Ekind (Base_T)));
-               Set_Parent (T, Obj_Def);
+               Set_Parent (T, Decl);
                Set_Scope (T, Current_Scope);
 
                if Ekind (T) = E_Array_Subtype then
-                  Constrain_Array (T, Obj_Def, Related_Nod, T, 'P');
+                  Constrain_Array (T, New_Def, Related_Nod, T, 'P');
 
                elsif Ekind (T) = E_Record_Subtype then
                   Set_First_Entity (T, First_Entity (Base_T));