]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Ada: Fix internal error on illegal aggregate for private type
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 11 Dec 2025 09:07:15 +0000 (10:07 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 11 Dec 2025 12:37:30 +0000 (13:37 +0100)
This just adds a guard for illegal cases to Resolve_Record_Aggregate.

gcc/ada/
PR ada/123088
* sem_aggr.adb (Resolve_Record_Aggregate): Add missing guard.

gcc/testsuite/
* gnat.dg/aggr33.adb: New test.

gcc/ada/sem_aggr.adb
gcc/testsuite/gnat.dg/aggr33.adb [new file with mode: 0644]

index 8e079f6b76addc7b4b42cd92d6d0ff07d53314fc..308bca6029896711f4e63ecc42017c8d2c3f2460 100644 (file)
@@ -6648,7 +6648,7 @@ package body Sem_Aggr is
          else
             Record_Def := Type_Definition (Parent (Base_Type (Typ)));
 
-            if Null_Present (Record_Def) then
+            if No (Record_Def) or else Null_Present (Record_Def) then
                null;
 
             --  Explicitly add here mutably class-wide types because they do
diff --git a/gcc/testsuite/gnat.dg/aggr33.adb b/gcc/testsuite/gnat.dg/aggr33.adb
new file mode 100644 (file)
index 0000000..7c307d8
--- /dev/null
@@ -0,0 +1,99 @@
+-- { dg-do compile }
+-- { dg-options "-gnat2022" }
+
+with Ada.Containers.Vectors;
+
+procedure Aggr33 is
+   type Light_Count is new Natural;
+   subtype Light_Position is Light_Count;
+
+   generic
+     Lights : Light_Position;
+
+   package Generic_Machine
+   is
+
+      subtype Light_State is Character
+        with Static_Predicate => Light_State in '.' | '#';
+
+      Off : constant Light_State := '.';
+      Lit : constant Light_State := '#';
+
+      type Panel_Type is
+        array (Light_Position range 0 .. Lights - 1) of Light_State;
+
+      Off_Panel : constant Panel_Type := [others => Off];
+
+      -----------------
+      -- Toggle_List --
+      -----------------
+
+      type Button_Index is new Positive;
+
+      package Toggle_Lists is new
+         Ada.Containers.Vectors (Index_Type   => Button_Index,
+                                 Element_Type => Light_Position);
+
+      subtype Toggle_List is Toggle_Lists.Vector;
+
+      ----------------
+      -- Press_List --
+      ----------------
+
+      package Press_Lists is new
+         Ada.Containers.Vectors (Index_Type   => Positive,
+                                 Element_Type => Toggle_Lists.Vector,
+                                 "="          => Toggle_Lists."=");
+
+      subtype Press_List is Press_Lists.Vector;
+
+      --------------------
+      -- Press_Sequence --
+      --------------------
+
+      subtype Press_Number is Natural;
+
+      type Press_Outcome is
+         record
+            Press : Toggle_List;
+            Panel : Panel_Type;
+         end record;
+
+      package Outcome_Lists is new
+         Ada.Containers.Vectors (Index_Type   => Press_Number,
+                                 Element_Type => Press_Outcome);
+
+      subtype Outcome_List is Outcome_Lists.Vector;
+
+      --------------
+      -- Sequence --
+      --------------
+
+      subtype Sequence_Id is Positive;
+
+      package Sequence_Lists is new
+         Ada.Containers.Vectors (Index_Type   => Sequence_Id,
+                                 Element_Type => Outcome_Lists.Vector,
+                                 "="          => Outcome_Lists."=");
+
+      subtype Sequence_List is Sequence_Lists.Vector;
+
+   end Generic_Machine;
+
+   package body Generic_Machine
+   is
+
+      procedure Add_Press
+      is
+         New_Sequence : Sequence_List;
+         Toggle       : Toggle_List;
+         New_Panel    : Panel_Type;
+      begin
+          New_Sequence.Append (Outcome_List'(Toggle, New_Panel)); -- { dg-error "too many components" }
+      end Add_Press;
+
+   end Generic_Machine;
+
+begin
+   null;
+end;