[Ada] Refine type for sorting case-choices tables

Message ID 20200611100009.GA90721@adacore.com
State New
Headers show
Series
  • [Ada] Refine type for sorting case-choices tables
Related show

Commit Message

Pierre-Marie de Rodat June 11, 2020, 10 a.m.
Tables with case-choices are sorted by Sort_Case_Table with an insertion
sort. Contrary to what comments for the Case_Table_Type says, this
routine doesn't use the table element at index 0 as a placeholder.

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

2020-06-11  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* sem_aggr.adb (Case_Table_Type): Change index type from Nat to
	Pos.

Patch

--- gcc/ada/sem_aggr.adb
+++ gcc/ada/sem_aggr.adb
@@ -85,9 +85,8 @@  package body Sem_Aggr is
       --  The node of the choice
    end record;
 
-   type Case_Table_Type is array (Nat range <>) of Case_Bounds;
-   --  Table type used by Check_Case_Choices procedure. Entry zero is not
-   --  used (reserved for the sort). Real entries start at one.
+   type Case_Table_Type is array (Pos range <>) of Case_Bounds;
+   --  Table type used by Check_Case_Choices procedure
 
    -----------------------
    -- Local Subprograms --
@@ -1827,9 +1826,8 @@  package body Sem_Aggr is
             --  if a choice in an aggregate is a subtype indication these
             --  denote the lowest and highest values of the subtype
 
-            Table : Case_Table_Type (0 .. Case_Table_Size);
-            --  Used to sort all the different choice values. Entry zero is
-            --  reserved for sorting purposes.
+            Table : Case_Table_Type (1 .. Case_Table_Size);
+            --  Used to sort all the different choice values
 
             Single_Choice : Boolean;
             --  Set to true every time there is a single discrete choice in a