This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]