]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix internal error on class-wide allocator inside if-expression
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 12 Dec 2023 17:05:40 +0000 (18:05 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 9 Jan 2024 13:13:31 +0000 (14:13 +0100)
The problem is that the freeze node for the class-wide subtype built for the
expression of the allocator escapes from the dependent expression instead of
being stored in its list of actions.

gcc/ada/

* freeze.adb (Freeze_Expression.Has_Decl_In_List): Deal specifically
with itypes that are class-wide subtypes.

gcc/ada/freeze.adb

index 26b5589a0208d0a3b1882c186490c2fdcfff56a9..468d6ee6dbee4a8f14657e5e803986cb732faa8b 100644 (file)
@@ -8141,10 +8141,19 @@ package body Freeze is
          Decl_Node : Node_Id;
 
       begin
-         --  If E is an itype, pretend that it is declared in N
+         --  If E is an itype, pretend that it is declared in N except for a
+         --  class-wide subtype with an equivalent type, because this latter
+         --  type comes with a bona-fide declaration node.
 
          if Is_Itype (E) then
-            Decl_Node := N;
+            if Ekind (E) = E_Class_Wide_Subtype
+              and then Present (Equivalent_Type (E))
+            then
+               Decl_Node := Declaration_Node (Equivalent_Type (E));
+            else
+               Decl_Node := N;
+            end if;
+
          else
             Decl_Node := Declaration_Node (E);
          end if;