diff mbox series

[Ada] Compiler crash on anonymous array with component with invariant

Message ID 20170908094506.GA59669@adacore.com
State New
Headers show
Series [Ada] Compiler crash on anonymous array with component with invariant | expand

Commit Message

Arnaud Charlet Sept. 8, 2017, 9:45 a.m. UTC
This patch fixes a compiler abort on an object declaration with an anonymous
array when the component type of the array has an invariant aspect.

The following must compile quietly:

   gcc -c -gnata main.adb


with Lrs;
procedure Main is
begin
   Lrs.Initialise;
end Main;
---
with Global;

package Lrs is
   type Quadrant_Specification is private;

   procedure Initialise;

private

   type Quadrant_Specification is record
      N_Klingons: Global.Klingon_Counter := 0;
      Has_Starbase: Boolean := False;
      N_Stars: Global.Local_Star_Counter := 0;
      Is_Scanned: Boolean := False;
   end record with
     Type_Invariant => N_Klingons <= Global.MAX_LOCAL_KLINGONS;

   Quadrant_Specifications: array(Global.Quadrant_X_Index'Range, 
                                  Global.Quadrant_Y_Index'Range)
     of Quadrant_Specification;
end Lrs;
---
package Global is
   MAX_KLINGONS: constant := 20;
   -- The maximum number of Klingons in the universe

   MAX_LOCAL_KLINGONS: constant := 3;
   -- The maximum number of Klingons in a quadrant

   MAX_LOCAL_STARS: constant := 8;
   -- The maximum number of stars in a quadrant

   UNIVERSE_SIZE: constant := 8;
   -- The X and Y size of the universe, in quadrants

   subtype Klingon_Counter is Integer range 0..MAX_KLINGONS;
   -- Type for the number of Klingons

   subtype Local_Star_Counter is Integer range 0..MAX_LOCAL_STARS;
   -- Type for the number of stars in a quadrant

   subtype Quadrant_X_Index is Integer range 1..UNIVERSE_SIZE;
   -- Subtype for quadrant X-indexes

   subtype Quadrant_Y_Index is Integer range 1..UNIVERSE_SIZE;
   -- Subtype for quadrant Y-indexes
end Global;

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

2017-09-08  Ed Schonberg  <schonberg@adacore.com>

	* exp_util.adb (Build_Invariant_Procedure_Declaration): If
	the type is an anonymous array in an object declaration, whose
	component type has an invariant, use the object declaration
	as the insertion point for the invariant procedure, given that
	there is no explicit type declaration for an anonymous array type.
diff mbox series

Patch

Index: exp_util.adb
===================================================================
--- exp_util.adb	(revision 251863)
+++ exp_util.adb	(working copy)
@@ -3408,7 +3408,12 @@ 
 
       --  Derived types with the full view as parent do not have a partial
       --  view. Insert the invariant procedure after the derived type.
+      --  Anonymous arrays in object declarations have no explicit declaration
+      --  so use the related object declaration as the insertion point.
 
+      elsif Is_Itype (Work_Typ) and then Is_Array_Type (Work_Typ)  then
+         Typ_Decl := Associated_Node_For_Itype (Work_Typ);
+
       else
          Typ_Decl := Declaration_Node (Full_Typ);
       end if;