]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix usage of Table.Table in Fmap
authorRonan Desplanques <desplanques@adacore.com>
Thu, 25 Sep 2025 07:53:35 +0000 (09:53 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 6 Oct 2025 12:27:09 +0000 (14:27 +0200)
Table.Table can be instantiated to use either 0-based or 1-based
indexing, which can cause some confusion and make 0-based instances get
used as 1-based ones.

This was the case for two tables in Fmap before this patch. That did not
cause any bugs but allocated an extra cell in the arrays that went
unused.

This patch also replaces Increment_Last-and-assignment combos with
equivalent calls to Append.

gcc/ada/ChangeLog:

* fmap.adb (File_Mapping, Path_Mapping): Fix instantiations.
(Add_To_File_Map): Use Table.Table.Append.

gcc/ada/fmap.adb

index f5e0540e0f8f9b44e77569b9023e85c7543fa9ca..4f20231365ddb22dd8442af18ba260efcfd777f0 100644 (file)
@@ -58,7 +58,7 @@ package body Fmap is
    package File_Mapping is new Table.Table (
      Table_Component_Type => Mapping,
      Table_Index_Type     => Int,
-     Table_Low_Bound      => 0,
+     Table_Low_Bound      => 1,
      Table_Initial        => 1_000,
      Table_Increment      => 1_000,
      Table_Name           => "Fmap.File_Mapping");
@@ -67,7 +67,7 @@ package body Fmap is
    package Path_Mapping is new Table.Table (
      Table_Component_Type => Mapping,
      Table_Index_Type     => Int,
-     Table_Low_Bound      => 0,
+     Table_Low_Bound      => 1,
      Table_Initial        => 1_000,
      Table_Increment      => 1_000,
      Table_Name           => "Fmap.Path_Mapping");
@@ -121,19 +121,15 @@ package body Fmap is
       if Unit_Entry = No_Entry or else
         File_Mapping.Table (Unit_Entry).Fname /= File_Name
       then
-         File_Mapping.Increment_Last;
+         File_Mapping.Append ((Uname => Unit_Name, Fname => File_Name));
          Unit_Hash_Table.Set (Unit_Name, File_Mapping.Last);
-         File_Mapping.Table (File_Mapping.Last) :=
-           (Uname => Unit_Name, Fname => File_Name);
       end if;
 
       if File_Entry = No_Entry or else
         Path_Mapping.Table (File_Entry).Fname /= Path_Name
       then
-         Path_Mapping.Increment_Last;
+         Path_Mapping.Append ((Uname => Unit_Name, Fname => Path_Name));
          File_Hash_Table.Set (File_Name, Path_Mapping.Last);
-         Path_Mapping.Table (Path_Mapping.Last) :=
-           (Uname => Unit_Name, Fname => Path_Name);
       end if;
    end Add_To_File_Map;